Iterating through 2 files simultaneously

G

glman74

Hi folks,

I am trying to tee off both stdout and stderr from a process run
through Popen.
As a test, I am first trying to print the output below:

from subprocess import Popen,PIPE
....
p1 = Popen(['cvs', 'update'], stdout=PIPE, stderr=PIPE)
for (l1, l2) in zip(p1.stdout, p1.stderr):
print '-->' + l1,
print '-->' + l2,

This doesn't work - probably because I cannot iterate through the
pipes this way.

I am new to Python, and I'd appreciate it if you could please explain
why this
doesn't work and/or suggest an alternate way to redirect stdout and
stderr to a
common place.

My objective is for my code to print out stdout/stderr messages and at
the same
time redirect them to a log file.

Thanks

Mahesh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top