title: Python subprocess supress stdout and stderr
body: <p>I call an external binary using the subprocess module:</p>
  
  <pre><code>try:
      subprocess.check_output([param1, param2], stderr=subprocess.STDOUT)
  except subprocess.CalledProcessError as e:
      print(e.output)
  </code></pre>
  
  <p>This outputs an error both when the <code>check_output</code> runs and in the except statement.
  What I really want to have is to print the output <strong>only if I catch an exception.</strong> So that means I want to have stderr in the exception object.</p>
  
  <p>The problem is that if I suppress the stdout:</p>
  
  <pre><code>subprocess.check_output(..., stdout=open(sys.os.devnull, 'wb'))
  </code></pre>
  
  <p>Then <code>e.output</code> sure becomes empty. Also I tried setting stderr to None - the same effect.</p>
  
  <p>How to add <code>stderr</code> to the <code>subprocess.CalledProcessError</code> instance without redirecting <code>stderr</code> to <code>stdout</code> because I do not need <code>stdout</code> at all.</p>