Grab input&output of program on Windows
Tero Pihlajakoski
tepihlaj at NOpaju.SPAMoulu.fi
Mon Jan 5 20:58:02 EST 2004
Patrick L. Nolan <pln at cosmic.stanford.edu> wrote:
> 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.
Sorry, if this is basic, but: Did you flush() after write()? Try using
popen2() (there was something about popen4() on win32...), if possible
(import popen2, etc.)?
> 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?
--
More information about the Python-list
mailing list