Grab input&output of program on Windows

Patrick L. Nolan pln at cosmic.stanford.edu
Tue Jan 6 01:40:15 CET 2004


I'm going nuts trying to port an application from Linux
to Windows.  We have a python/Tkinter script which runs
a C++ application.  It starts it with popen4 and 
communicates through the two pipes.  It reads text output
from stdout until a prompt appears, then sends commands
through stdin.

On Windows it seems to get all tangled up in the buffering
of the two streams.  When the script just reads stdout, it
seems to be OK.  As soon as the first command is sent to
stdin, stdout blocks forever.

I tried borrowing an idea from the Python Cookbok, recipe
9.6.  I made the streams nonblocking and put a call to
select in a loop.  The results were promising on Linux,
but there was a mysterious error message on Windows.
I think select works only for sockets, not pipes.

This seems like the sort of thing that might be solved by
expect.  Will that work?  Is there some other way?

-- 
*   Patrick L. Nolan                                          *
*   W. W. Hansen Experimental Physics Laboratory (HEPL)       * 
*   Stanford University                                       *



More information about the Python-list mailing list