How to use subprocess when multiple arguments contain spaces?

后端 未结 10 2247

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

    I believe that list2cmdline(), which is doing the processing of your list args, splits any string arg on whitespace unless the string contains double quotes. So I would expect

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

    to be what you want.

    You'll also likely want to surround the other arguments (like target_vm) in double quotes on the assumption that they, too, each represent a distinct arg to present to the command line. Something like

    r'"%s"' % target_vm
    

    (for example) should suit.

    See the list2cmdline documentation

    D'A

提交回复
热议问题