How to use subprocess when multiple arguments contain spaces?

后端 未结 10 2245

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:40

    'c:\Program' is not recognized as an internal or external command,
    operable program or batch file.
    

    To get this message, you are either:

    1. Using shell=True:

      vmrun_cmd = r"c:\Program Files\VMware\VMware Server\vmware-cmd.bat"
      subprocess.Popen(vmrun_cmd, shell=True)
      
    2. Changing vmrun_cmd on other part of your code

    3. Getting this error from something inside vmware-cmd.bat

    Things to try:

    • Open a python prompt, run the following command:

      subprocess.Popen([r"c:\Program Files\VMware\VMware Server\vmware-cmd.bat"])
      

    If that works, then quoting issues are out of the question. If not, you've isolated the problem.

提交回复
热议问题