How do i get output from pope3 while process is running?

Donn Cave donn at oz.net
Sat Dec 4 01:15:12 EST 1999


Quoth Andrew Patterson <andrew at fc.hp.com>:
| I want to run an extremely long running external command and send its output
| to stdout of my python program.  I started with os.system which works fine
| except that I needed to capture the stderr output in a separate stream.  The
| popen2.Popen3 class seems to fit the bill, however, I can not get any of the
| output until the process finishes (hours later).  Here is the code I am using:

It's not your code, it's the external command.  It buffers up all its
output and doesn't write anything to the pipe until the exit flushes
the output buffer.  This is standard for C library I/O (stdout) to
devices other than a tty, but if you can rewrite the command, all it
needs is a fflush(stdout) after any interesting output.

Otherwise, it's a much bigger headache, because you need a tty for it.
This means a pseudo-tty, a two-way pipe that works like a terminal.
The most popular software for this technique is a Tcl application called
"Expect", and there are Python variations but I don't know exactly where
we stand on that today.

	Donn Cave, University Computing Services, University of Washington
	donn at u.washington.edu




More information about the Python-list mailing list