title: Store value of os.system or os.popen
body: <p>I want to grep the error's out of a log file and save the value as an error. When I use:</p>
  
  <pre><code>errors = os.system("cat log.txt | grep 'ERROR' | wc -l")
  </code></pre>
  
  <p>I get the return code that the command worked or not. When I use:</p>
  
  <pre><code>errors = os.popen("cat log.txt | grep 'ERROR' | wc -l")
  </code></pre>
  
  <p>I get what the command is trying to do.</p>
  
  <p>When I run this in the command line I get 3 as thats how many errors there are.</p>
  
  <p>Can anyone suggest another way in Python that will allow me to save the value of this bash command?</p>
  
  <p>Thanks</p>