How to use subprocess when multiple arguments contain spaces?

后端 未结 10 2162

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

    One problem is that if the command is surrounded with quotes and doesn't have spaces, that could also confuse the shell.

    So I do this:

    if ' ' in raw_cmd:
        fmt = '"%s"'
    else:
        fmt = '%s'
    
    cmd = fmt % raw_cmd
    

提交回复
热议问题