Grab input&output of program on Windows

  • Thread starter Patrick L. Nolan
  • Start date
P

Patrick L. Nolan

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?
 
T

Tero Pihlajakoski

Patrick L. Nolan said:
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?


--
 
P

Patrick L. Nolan

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.)?

Thanks. I skimped on the details to avoid scaring off potential
readers. Yes, I did try flushing the streams. I'm using
win32pipe.popen4() on windows and popen2.popen4() on linux.
Win32pipe is supposed to be the one that works....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top