title: How to capture the output from "subprocess.call" to a file?
body: <p>In my code I have a line similar to this:</p>
  
  <pre><code>rval = subprocess.call(["mkdir",directoryName], shell=True)
  </code></pre>
  
  <p>and I can check <code>rval</code> to see if it is <code>0</code> or <code>1</code>, but if it is <code>1</code>, I would like to have the text from the command <code>"A subdirectory or file ben already exists."</code> in a file format, so I can compare it to another file if I want to make sure the text is the same.</p>
  
  <p>Is it possible to have a line like this, but I know this does not work</p>
  
  <pre><code>rval = subprocess.call(["mkdir",directoryName], shell=True) &gt;&gt; filename
  </code></pre>
  
  <p>so no matter what happens with the command, the text is captured in <code>filename</code>, and <code>rval</code> still has the return code?</p>