I used to be able to do a subprocess.call(["command","-option value -option value"])
and it would work there was a change to the command to work properly with things in quotes, but now I have to change my subprocess call command to look like this:
subprocess.call(["command","-option","value","-optio开发者_如何学Gon","value"])
is there something I can do to get it to work the other way again in python?
the os.system("command -option value -option value")
works the same as it did before.
Avoid shell=True
if you can -- it's a security risk. For this purpose, shlex.split suffices:
import subprocess
import shlex
subprocess.call(shlex.split("command -option value -option value"))
You'll need to specify shell=True
to get subprocess.call to interpret the string.
See the note in the subprocess.Popen constructor documentation (the subprocess.call method takes the same arguments as the subprocess.Popen constructor).
精彩评论