title: Using subprocess for compiling a c++ program from python script
body: <p>I know there are some similar questions, here <a href="https://stackoverflow.com/questions/24738107/invoking-c-compiler-using-python-subprocess-command">Invoking C compiler using Python subprocess command</a> and <a href="https://stackoverflow.com/questions/49541728/subprocess-invoke-c-program-from-within-python">subprocess, invoke C-program from within Python</a> but I believe my question is in some sense different. </p>
  
  <p>I need to compile a c++ program which uses some <a href="https://root.cern.ch/" rel="nofollow noreferrer">ROOT</a> libraries so I need to add some flags and link some libraries for the compilation. Therefore my compilation line on the normal shell is:</p>
  
  <pre><code>&gt; $($ROOTSYS/bin/root-config --cxx) $($ROOTSYS/bin/root-config --cflags --glibs) Analysis.cxx -o analysis.exe
  </code></pre>
  
  <p>which works nicely. I want to do this compilation from my python script. I have read the documentation for the <a href="https://docs.python.org/3.4/library/subprocess.html#module-subprocess" rel="nofollow noreferrer">subprocess</a> module but I could not get a solution without using <code>shell=True</code> in the call of subprocess.Popen and I do not really undestand the difference. If I use:</p>
  
  <pre><code>process = Popen(["$($ROOTSYS/bin/root-config --cxx) $($ROOTSYS/bin/root-config --cflags --glibs) Analysis.cxx -o analysis.exe"], shell=True)
  </code></pre>
  
  <p>does the job. However, this:</p>
  
  <pre><code>process = Popen(["$($ROOTSYS/bin/root-config --cxx)", "$($ROOTSYS/bin/root-config --cflags --glibs)", "Analysis.cxx", "-o", "analysis.exe"])
  </code></pre>
  
  <p>I got the following:</p>
  
  <pre><code>    Traceback (most recent call last):
    File "make_posanalysis.py", line 45, in &lt;module&gt;
      "Analysis.cxx", "-o", "analysis.exe"])
    File "Python/2.7.15/x86_64-slc6-gcc62-opt/lib/python2.7/subprocess.py", line 394, in __init__
      errread, errwrite)
    File "Python/2.7.15/x86_64-slc6-gcc62-opt/lib/python2.7/subprocess.py", line 1047, in _execute_child
      raise child_exception
  OSError: [Errno 2] No such file or directory
  </code></pre>
  
  <p>I would like to understand the difference between using/not using <code>shell=True</code> since it seems to be the reason behind making the script work or not. Or, is there something else I am missing?</p>