[Chicago] capturing output from subprocesses

Noel Thomas Taylor nttaylor at uchicago.edu
Tue Nov 8 01:12:14 CET 2005


Dear Chicago Python Hackers,

I just joined the list and hope to come to the meeting this Thursday. If I 
can't, however, I wonder if someone could help me with a very tricky 
problem...

A couple of months ago I started trying to find a way to launch a
subprocess in python that would allow the parent to capture the stdout
and stderr of the child, time the duration of the child, and abort the
child if it had failed to produce output after 'n' seconds. Also, the
solution should perform consistently across all Unices (Windows doesn't
matter) and if the child must be aborted, whatever output it produced up
to that point should still be captured.

There are several solutions out there, but most do not capture the output 
of the child in real time. You always have to wait for the child to 
terminate until you can see any of its output, and consequently if the 
child must be aborted because it gets stuck, you lose whatever output it 
generated before you killed it.

For several weeks I've been trying to use Noah Spurrier's "pexpect"
module, which uses pseudo-terminals to get around the above issue, but
pseudo-terminals do not perform consistently across platforms, and pexpect
fails under IRIX. Does anyone know if there is a way to solve the above 
problem with out pseudo-terminals?

I would greatly appreciate any knowledge any of you have to impart. Like I 
mentioned, I'm only concerned that this work on Unix/Linux/Irix, etc 
(though Mac OSX would be nice). The subprocess-launching code should be in 
python, but the child code might be python, fortran, or a shell script. 
What do you think?

with thanks in advance,

Noel Taylor


More information about the Chicago mailing list