Using popen interactively

Kragen Sitaker kragen at
Sun Jun 9 04:43:36 CEST 2002

[note Joe is talking about a game by a guy named Don about a cave, or
a derivative thereof]

"Donn Cave" <donn at> writes:
> Quoth Joe Mason <joe at>:
> ...
> | So I'm trying to use popen2.Popen3("executable-name") to get handles to
> | stdin and stdout.  Works fine, except that I'm not sure how to detect
> | when the app has stopped printing and is waiting for input.  readline()
> Right.  I expect you'd do better to throw away the file objects
> popen2 makes for you, and use the pipe file descriptors directly.
> Instead of
>     infile = app.fromchild
>     ...
>         line = infile.readline()
> say
>     infile = app.fromchild.fileno()
>     ...
>         data =, 8192)

But not too soon --- if the program does multiple writes, this might
return before the last of them.

>         #  split into lines if you care
> The stdio buffering in a file object is only trouble for you.
> Part of this trouble is on the other end, if your external
> process buffers output - in that case you'll have to figure
> out how to use ptys.
> 	Donn Cave, donn at

More information about the Python-list mailing list