title: Python Not Waiting for MATLAB to Finish
body: <p>I am interfacing a small MATLAB script with Python via the <code>subprocess</code> module. As follows:</p>
  
  <pre><code>cmd='(matlab -nosplash -nodesktop -r "optimizer;quit;")'
  p = subprocess.Popen(cmd,stdin=None,stdout=None,shell=True)
  #subprocess.Popen.wait(p)
  #p.wait()
  print "DONE?"
  </code></pre>
  
  <p>But "DONE" is being printed even before MATLAB starts! My entire code past it is breaking because of this.</p>
  
  <p>I have tried:</p>
  
  <ul>
  <li>Using os.system() calls (This is where I started, but I read on SO that its deprecated)</li>
  <li>Using <code>p.wait()</code> and <code>subprocess.Popen.wait</code>. Both don't work.</li>
  <li>Using a manual pause of 3 minutes (Max. time MATLAB takes to finish on average) <em>Super Sloppy</em>.</li>
  </ul>
  
  <p>What am I missing?</p>