How to use subprocess when multiple arguments contain spaces?

后端 未结 10 2243

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

    Here's what I don't like

    vmrun_cmd = r"c:/Program Files/VMware/VMware Server/vmware-cmd.bat"
    

    You've got spaces in the name of the command itself -- which is baffling your shell. Hence the "'c:\Program' is not recognized as an internal or external command, operable program or batch file."

    Option 1 -- put your .BAT file somewhere else. Indeed, put all your VMWare somewhere else. Here's the rule: Do Not Use "Program Files" Directory For Anything. It's just wrong.

    Option 2 -- quote the vmrun_cmd value

    vmrun_cmd = r'"c:/Program Files/VMware/VMware Server/vmware-cmd.bat"'
    

提交回复
热议问题