Reading from a pipe (open mode w)

Donn Cave donn at u.washington.edu
Thu Jan 4 13:02:49 EST 2001


Quoth "Jens Vogelgesang" <jens.vogelgesang at de.bosch.com>:
| I need a wrapper to capsulate an interactive tool which is waiting for
| keyboard input.
| I can generate the input by writing into the pipe.
| To be able to retrieve the tool output, I tried to read from the pipe.
| My Problem is, that I don't know, how to flush the pipe, to force the pipe
| not to be buffered??

Python 2.0 has new pseudotty support for some platforms.  If you're
using UNIX here, it's worth looking into this - at least, import posix
and see if posix.openpty is there.  There's a Python pty module that
provides some higher level support.

The pseudotty is a pipe-like device that acts like a tty - it's duplex,
and it recognizes the terminal ioctls.  The point here, though, is that
the I/O functions of the other program are probably written in C stdio
(or similar), which buffers output when it discovers it's writing to
a device other than a tty.  To defeat the buffering, you have to present
the program with a tty device.

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list