title: How do I execute a program from Python? os.system fails due to spaces in path
body: <p>I have a Python script that needs to execute an external program, but for some reason fails.</p>
  
  <p>If I have the following script:</p>
  
  <pre><code>import os;
  os.system("C:\\Temp\\a b c\\Notepad.exe");
  raw_input();
  </code></pre>
  
  <p>Then it fails with the following error:</p>
  
  <blockquote>
    <p>'C:\Temp\a' is not recognized as an internal or external command, operable program or batch file.</p>
  </blockquote>
  
  <p>If I escape the program with quotes:</p>
  
  <pre><code>import os;
  os.system('"C:\\Temp\\a b c\\Notepad.exe"');
  raw_input();
  </code></pre>
  
  <p>Then it works. However, if I add a parameter, it stops working again:</p>
  
  <pre><code>import os;
  os.system('"C:\\Temp\\a b c\\Notepad.exe" "C:\\test.txt"');
  raw_input();
  </code></pre>
  
  <p>What is the right way to execute a program and wait for it to complete? I do not need to read output from it, as it is a visual program that does a job and then just exits, but I need to wait for it to complete.</p>
  
  <p>Also note, moving the program to a non-spaced path is not an option either.</p>
  
  <hr>
  
  <p>This does not work either:</p>
  
  <pre><code>import os;
  os.system("'C:\\Temp\\a b c\\Notepad.exe'");
  raw_input();
  </code></pre>
  
  <p>Note the swapped single/double quotes.</p>
  
  <p>With or without a parameter to Notepad here, it fails with the error message</p>
  
  <blockquote>
    <p>The filename, directory name, or volume label syntax is incorrect.</p>
  </blockquote>