I am trying to execute my python script in java using jython. The important thing is that I need to pass command line arguments to my script using jython, e.g. myscript.py arg1 arg2 arg3. There is a similar question here: Passing arguments to Python script in Java
Which was not answered completely (none of the solutions work).
My code now looks like this:
String[] arguments = {"arg1", "arg2", "arg3"};
PythonInterpreter.initialize(props, System.getProperties(), arguments);
org.python.util.PythonInterpreter python = new org.python.util.PythonInterpreter();
StringWriter out = new StringWriter();
python.setOut(out);
python.execfile("myscript.py");
String outputStr = out.toString();
System.out.println(outputStr);
However, this does not seem to pass any arguments to the python script. Any suggestions how to do it properly? It must be simple, but I can't find any documentation on the web.
I am using python 2.7 and jython 2.7.0.