title: Python's Subprocess.Popen With Shell=True. Wait till it is completed
body: <p>Submitting a complex <strong>cmd</strong> string made of a full file path to an executable, the multiple flags, arguments, parameters, inputs and outputs seems to require me to set <strong>shell=True</strong> otherwise subprocess.Popen is not able understand anything more complex than just a simple path to executable (with no spaces in a filepath).</p>
  
  <p>In my example I have quite a long cmd:</p>
  
  <pre><code>cmd = " '/Application/MyApp.app/Contents/MacOS/my_executable' '/Path/to/input/files' -some -flags -here -could -be -a -lot '/full/path/to/output/files' "
  </code></pre>
  
  <p>Submitting this cmd to <strong>subprocess.Popen</strong> " results to an error that complains on something about the path and not being able to find it.</p>
  
  <p>So instead of using :</p>
  
  <pre><code>proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  </code></pre>
  
  <p><strong>check_call</strong> seems workings quite well:</p>
  
  <pre><code>proc = subprocess.check_call(cmd, shell=True)
  </code></pre>
  
  <p>Interesting, only after <strong>shell</strong> is set to <strong>True</strong> </p>
  
  <pre><code>shell=True 
  </code></pre>
  
  <p>the <strong>subprocess.check_call</strong> works with a supplied cmd. </p>
  
  <p>The side effect is that the rest of the code seems proceeds running without waiting for <strong>subprocess.check_call(cmd, shell=True)</strong> to finish first.</p>
  
  <p>The code is designed the way that the rest of the execution is dependent on a result of <code>subprocess.check_call(cmd, shell=True)</code>. </p>
  
  <p>I wonder if there is anyway to enforce the code execution to wait till subprocess.check_call(cmd, shell=True) is finished. Thanks in advance!</p>