aspose file tools*
The moose likes Jython/Python and the fly likes Calling a jython function from command prompt. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Jython/Python
Bookmark "Calling a jython function from command prompt." Watch "Calling a jython function from command prompt." New topic
Author

Calling a jython function from command prompt.

Ouney Gags
Greenhorn

Joined: Jan 23, 2011
Posts: 8
Hi,


I am very-2 new to jython and writing first jython script.
Jython script :-

Where ReadProp is a java class :-

Now, i want t invoke this jython function (funtion1) from command line.
If, i modify my jython file to


I works fine and i can see the properties file values. (i invoke the py file directly from command prompt).
But when i put it in function, it does not work.
i have tried passing the function name with -c option but still it fails silently.
Could anybody tell me how to call a jython file from command prompt (for a specific function)?
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

In python there is no 'main()' type function or method. Any code that is not part of a function or class is executed when the file is loaded. So when you define a function in a file, the function is parsed but not executed. To execute it you would need to add a line:


Since you might also want to import this code into other modules, you might want to prevent the function from running automatically. In that case you look at the value of the __name__, if it is "__main__" the code is being executed directly by the interpreter and not being imported as a module (if it were imported as a module the __name__ would be the name of the file). So a typical thing to do when you want to run a function automatically from the command line would be:


Steve
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Calling a jython function from command prompt.