I’m trying to execute the following line of code:
subprocess.call(["java", "-cp", "/home/me/somepath/file.jar", ..., "-someflag somevalue"])
The code fails and the jar I’m trying to run gives me usage information. But if I expand out the string and paste it into the terminal, it works (I know I’m expanding the string out correctly because the sh module spits it back to me when it errors out). So this is an issue with how either subprocess or sh operates.
Here’s an example of how you’re supposed to use it:
subprocess.call(["ls", "-l"])
Here’s the description:
subprocess.check_call(args, *, stdin=None, stdout=None, stderr=None, shell=False)
args is required for all calls and should be a string, or a sequence
of program arguments. Providing a sequence of arguments is generally
preferred, as it allows the module to take care of any required
escaping and quoting of arguments (e.g. to permit spaces in file
names). If passing a single string, either shell must be True (see
below) or else the string must simply name the program to be executed
without specifying any arguments.
http://docs.python.org/2/library/subprocess.html
It’s not clear to me if I should be breaking up the strings in the list with flags and values in separate places.
Your original code corresponds to
in the shell.