I am using Python 2.7.1 in a Windows Server 2008 R2 x64 window.
I am trying to get the result of a command line process that gives a non-zero exit status after the output of the information I need.
At first I used subprocess.check_output and caught a CalledProcessError that met with non-zero exit status, but while the return code was saved in error, not a single result found this.
Running this for cases that produce output but has exit status 0 works correctly, and I can get the output using subprocess.check_output.
My guess was that the output was written to STDOUT, but the exception deduced its “output” from STDERR. I tried to implement the check_output functionality, but I still don't get anything in the output when I consider that I should see the output of STDOUT and STDERR. My current code is below (where the "command" is the full text, including the parameters, of the command I am running:
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
This gives me the following in the output of the variable: [('', None)]
Is my subprocess.Popen code correct?
python subprocess stdout stderr windows-server-2008-r2
bplattenburg
source share