• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Calling a jython function from command prompt.

Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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)?
Posts: 4179
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic