subprocess.call requiring all parameters to be separated by commas

后端 未结 2 1773
迷失自我
迷失自我 2020-12-30 01:33

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

相关标签:
2条回答
  • 2020-12-30 02:04

    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 讨论(0)
  • 2020-12-30 02:26

    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"))
    
    0 讨论(0)
提交回复
热议问题