My python code spawns the child process, and it prints out messages both stdout and stderr.
I need to print them differently.
I have the following code to spawn child process and get the stdout result from it.
cmd = ["vsmake.exe", "-f"]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
for line in iter(p.stdout.readline, ''):
print line,
sys.stdout.flush()
pass
p.wait()
How can I modify the code to check if the child process prints out message through stderr also?
ADDED
I need to print out the stderr and stdout as soon as the child process prints out something. And it is cross platform implementation, so it should run on Mac/Linux/PC.
So basically the error output gets redirected to the
stderrPipe.If you need something more in real in time. I mean lines printed as soon as the spawned process prints something to
stdout orstderr` then you can do something like:In this case two threads will print every time that a line is written either to
stdoutorstderr. The parametertype_pipejust makes the distinction when the lines are printed to know if they are coming fromstderrorstdout.