title: Advantages of subprocess over os.system
body: <p>I have recently came across a few posts on stack overflow saying that subprocess is much better than os.system, however I am having difficulty finding the exact advantages. </p>
  
  <p>Some examples of things I have run into:
  <a href="https://docs.python.org/3/library/os.html#os.system" rel="noreferrer">https://docs.python.org/3/library/os.html#os.system</a></p>
  
  <blockquote>
    <p>"The subprocess module provides more powerful facilities for spawning new processes and retrieving their results; using that module is preferable to using this function."</p>
  </blockquote>
  
  <p>No idea in what ways it is more powerful though, I know it is easier in many ways to use subprocess but is it actually more powerful in some way?</p>
  
  <p>Another example is:</p>
  
  <p><a href="https://stackoverflow.com/a/89243/3339122">https://stackoverflow.com/a/89243/3339122</a></p>
  
  <blockquote>
    <p>The advantage of <strong>subprocess</strong> vs <strong>system</strong> is that it is more flexible (you can get the stdout, stderr, the "real" status code, better error handling, etc...).</p>
  </blockquote>
  
  <p>This post which has 2600+ votes. Again could not find any elaboration on what was meant by better error handling or real status code. </p>
  
  <p>Top comment on that post is:</p>
  
  <blockquote>
    <p>Can't see why you'd use os.system even for quick/dirty/one-time. subprocess seems so much better. </p>
  </blockquote>
  
  <p>Again, I understand it makes some things slightly easier, but I hardly can understand why for example:</p>
  
  <pre><code>subprocess.call("netsh interface set interface \"Wi-Fi\" enable", shell=True)
  </code></pre>
  
  <p>is any better than</p>
  
  <pre><code>os.system("netsh interface set interface \"Wi-Fi\" enabled")
  </code></pre>
  
  <p>Can anyone explain some reasons it is so much better?</p>