Watching output and put back in background

andrea crotti andrea.crotti.0 at gmail.com
Thu Oct 18 09:05:58 EDT 2012


In one process I need to run many quite weird shell commands that take a
long time, possibly in parallel.

Now the problem is that I need to catpure the initial standard error of
the command and then I can go on with the second one, but how can I do
that?

It should be something like

Popen(long_command..)

- first line output
- second line
- interesting line

.. more things ..

But if I just do

out, err = proc.communicate()

it will hang there until the end, right?

Maybe a solution would be to redirect the stderr to file and watch that
instead..

Or otherwise I could use a thread for each shell command, but I would
like to avoid head-aches with possible race-conditions..

Ideas?



More information about the Python-list mailing list