title: How to use subprocess when multiple arguments contain spaces?
body: <p>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 trying to use subprocess to handle invoking the executable, but the spaces in the executables path and in parameters of the executable are not being handled correctly by subprocess.  Below is a code fragment:</p>
  
  <pre><code>vmrun_cmd = r"c:/Program Files/VMware/VMware Server/vmware-cmd.bat"
  def vm_start(target_vm):
      list_arg = "start"
      list_arg2 = "hard"
      if vm_list(target_vm):
              p = Popen([vmrun_cmd, target_vm, list_arg, list_arg2],   stdout=PIPE).communicate()[0]
              print p
      else:
              vm_register(target_vm)
              vm_start(target_vm)
  def vm_list2(target_vm):
      list_arg = "-l"
      p = Popen([vmrun_cmd, list_arg], stdout=PIPE).communicate()[0]
      for line in p.split('\n'):
              print line
  </code></pre>
  
  <p>If I call the vm_list2 function, I get the following output:</p>
  
  <pre><code>$ ./vmware_control.py --list                                                
  C:\Virtual Machines\QAW2K3Server\Windows Server 2003 Standard Edition.vmx
  C:\Virtual Machines\ubunturouter\Ubuntu.vmx
  C:\Virtual Machines\vacc\vacc.vmx
  C:\Virtual Machines\EdgeAS-4.4.x\Other Linux 2.4.x kernel.vmx
  C:\Virtual Machines\UbuntuServer1\Ubuntu.vmx
  C:\Virtual Machines\Other Linux 2.4.x kernel\Other Linux 2.4.x kernel.vmx
  C:\Virtual Machines\QAClient\Windows XP Professional.vmx
  </code></pre>
  
  <p>If I call the vm_start function, which requires a path-to-vm parameter, I get the following output:</p>
  
  <pre><code>$ ./vmware_control.py --start "C:\Virtual Machines\ubunturouter\Ubuntu.vmx"
  'c:\Program' is not recognized as an internal or external command,
  operable program or batch file.
  </code></pre>
  
  <p>Apparently, the presence of a second parameter with embedded spaces is altering the way that subprocess is interpreting the first parameter.  Any suggestions on how to resolve this?</p>
  
  <p>python2.5.2/cygwin/winxp</p>