[Chicago] capturing output from subprocesses

Martin Maney maney at two14.net
Tue Nov 8 14:49:29 CET 2005

On Mon, Nov 07, 2005 at 06:12:14PM -0600, Noel Thomas Taylor wrote:
> 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?

Nope.  The problem is that the child processes are internally buffering
their output when attached to a file-like sink, so there's nothing
coming out of them until (a) the internal buffer fills and gets
flushed, (b) the subprocess manually flushes the buffer, or (c) normal
termination casues all buffers to be flushed.  PTYs fix that because
the stdio library handles them differently (I think it goes to
line-oriented flushing mode, but that's an old, possibly nonstandard,

> 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?

Okay, one other way to fix it: if you can pass an option to tell the
program to use unbuffered (or line buffered) output (but that's rarely
available), or if you can alter the program itself, you can get
immediate output through a pipe.  Otherwise, PTYs are probably as
portable a solution as there is, to my knowledge.

People make secure systems insecure because
insecure systems do what people want and
secure systems don't.  -- James Grimmelmann

More information about the Chicago mailing list