How to use subprocess when multiple arguments contain spaces?

后端 未结 10 2160

I\'m working on a wrapper script that will exercise a vmware executable, allowing for the automation of virtual machine startup/shutdown/register/deregister actions. I\'m t

10条回答
  •  一生所求
    2021-01-07 18:27

    In Python on MS Windows, the subprocess.Popen class uses the CreateProcess API to started the process. CreateProcess takes a string rather than something like an array of arguments. Python uses subprocess.list2cmdline to convert the list of args to a string for CreateProcess.

    If I were you, I'd see what subprocess.list2cmdline(args) returns (where args is the first argument of Popen). It would be interesting to see if it is putting quotes around the first argument.

    Of course, this explanation might not apply in a Cygwin environment.

    Having said all this, I don't have MS Windows.

提交回复
热议问题