title: Python: get output from a command line which exits with nonzero exit code
body: <p>I am Using <code>Python 2.7.1</code> on a Windows Server 2008 R2 x64 box.</p>
  
  <p>I'm trying to get the output of a command line process which gives a nonzero exit status after outputting the information I need.</p>
  
  <p>I was initially using <code>subprocess.check_output</code>, and catching the CalledProcessError which occurs with nonzero exit status, but while the returncode was stored in the error, no output revealed this. </p>
  
  <p>Running this against cases which give output but have an exit status of 0 works properly and I can get the output using subprocess.check_output.</p>
  
  <p>My assumption was that the output was being written to STDOUT but the exception pulls its 'output' from STDERR. I've tried to re implement the functionality of check_output, but I still get nothing on the output when I believe I should be seeing output to STDOUT and STDERR. My current code is below (where 'command' is the full text, including parameters, of command I am running:</p>
  
  <pre><code>process = subprocess.Popen(command, stdout=subprocess.PIPE, 
  stderr=subprocess.STDOUT, universal_newlines=True)
  output = process.communicate()
  retcode = process.poll()
  if retcode:
      raise subprocess.CalledProcessError(retcode, image_check, output=output)
      return output 
  </code></pre>
  
  <p>This gives me the following in the variable output: <code>[('', None)]</code></p>
  
  <p>Is my <code>subprocess.Popen</code> code correct?</p>