开发者

subprocess.call requiring all parameters to be separated by commas

开发者 https://www.devze.com 2023-01-23 15:12 出处:网络
I used to be able to do a subprocess.call([\"command\",\"-option value -option value\"])and it would workthere was a change to the command to work properly with things in quotes, but now I have to cha

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消