Python Subprocess Call With Whitespaces In Arguments Doesn't Work On Windows
I am running a java command which takes the classpath and other file locations which have a white space. Windows doesn't seem to like it. I have the program running from C:\Progra
Solution 1:
Don't use shell=True
. The docs state you only need shell=True
on Windows if using a command actually built-into the shell:
The only time you need to specify shell=True on Windows is when the command you wish to execute is built into the shell (e.g. dir or copy). You do not need shell=True to run a batch file or console-based executable.
If you aren't using shell=True
, you can pass the arguments as a list, and not worry about spaces being treated incorrectly by the shell.
p = subprocess.Popen(['java', '-Xmx20m', '-Dlog4j.configuration=file:%s' % log4j,
'-cp', classpath, 'org.apache.flume.node.Application',
'-f', flumeconf, '-n', 'agent1'], stdout=subprocess.PIPE)
Post a Comment for "Python Subprocess Call With Whitespaces In Arguments Doesn't Work On Windows"