473,507 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Grab input&output of program on Windows

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 *
Jul 18 '05 #1
2 1859
Patrick L. Nolan <pl*@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?

--

Jul 18 '05 #2
Tero Pihlajakoski <te******@nopaju.spamoulu.fi> wrote:
Patrick L. Nolan <pl*@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.)?


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

--
* Patrick L. Nolan *
* W. W. Hansen Experimental Physics Laboratory (HEPL) *
* Stanford University *
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2674
by: Glutinous | last post by:
Trying to learn php, and came across =& as in $form =& $HTTP_POST_VARS; I can't find any reference to =&, with no success in searching for a definition (as though it's _so_ obvious it...
4
4080
by: sonic_soul | last post by:
Hi, I was curious if I could make my webservice work with firefox client webservice functionality. (i got it to work with webservice.htc) I am able to get firefox to see my serverside web...
2
6449
by: yee young han | last post by:
I need a fast data structure and algorithm like below condition. (1) this data structure contain only 10,000 data entry. (2) data structure's one entry is like below typedef struct _DataEntry_...
7
7870
by: LineVoltageHalogen | last post by:
Greetings All, I have a very large query that uses dynamic sql. The sql is very large and it requires it to be broken into three components to avoid the nvarchar(4000) issue: SET @v_SqlString(...
8
1586
by: Gemma Fletcher | last post by:
Hi all :) I'm implementing a menu system for my assignment. User inputs command & an if/else switch statement executes the command. I'm just not quite sure the best way to take user input. ...
7
1894
by: Taras_96 | last post by:
Hi all, I was hoping to get some clarification on a couple of questions I have: 1) When should htmlspecial characters be used? As a general rule should it be used for text that may contain...
7
1706
by: arnuld | last post by:
this is the programme which converts a string of digits into its numeric equivalent, given in section 2.7: /* atoi: convert s to integer */ int atoi(char s) { int i, n; n = 0; for (i = 0;...
2
2002
by: ayan4u | last post by:
ok i have two problems... firstly in strict C enviornment is it possible to have a true dynamic charecter array with no predefined length...i mean to say... suppose.. char *array =NULL;...
16
4809
by: Okonita via DBMonster.com | last post by:
Hi all, I am comming along with all this Linus/DB2/scripting business...I am no longer scared of it!! (LOL). But, I need to create a .ksh script that does a REORGCHK and output only tables...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7111
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7031
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5042
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1542
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.