How to use subprocess when multiple arguments contain spaces?

后端 未结 10 2157

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

    Possibly stupid suggestion, but perhaps try the following, to remove subprocess + spaces from the equation:

    import os
    from subprocess Popen, PIPE
    
    os.chdir(
        os.path.join("C:", "Program Files", "VMware", "VMware Server")
    )
    
    p = Popen(
        ["vmware-cmd.bat", target_vm, list_arg, list_arg2],
        stdout=PIPE
    ).communicate()[0]
    

    It might also be worth trying..

    p = Popen(
        [os.path.join("C:", "Program Files", "VMware", "VMware Server", "vmware-cmd.bat"), ...
    

提交回复
热议问题