0

This question is very similar to this one. I want to read output from a console app of mine. The app does not terminate, nor does it take input from stdin.

When I modify rix0rrr's solution to execute my app and then run his solution, Python hangs because read(1) does not return. The initial output of the app is "Starting the server.\n". Can you guess what property my app may have that is preventing his solution from working? The extent of my changes is that I changed this:

p = Popen( ["cmd.exe"], stdin=PIPE, stdout=PIPE )
prompt = re.compile(r"^C:\\.*>", re.M)

to this:

p = Popen( ["c:\\path\\to\\my\\app\\app.exe"], stdin=PIPE, stdout=PIPE )
prompt = re.compile(r"Starting", re.M)
import pdb;pdb.set_trace()

I also created a test version of my app that returns immediately and verified that the output from the app is returned by read() in that case. His original, unmodified example, as expected, also does not hang.

I also tried out the ActiveState code that Piotr linked to in his answer. No output is returned from the process in that case, either.

This is Python 2.4.4 on Vista.

1
  • You need to show more of the code, including how you're reading the process' STDOUT Commented Nov 6, 2009 at 6:08

1 Answer 1

1

The very first thing I would check is the buffering in app.exe. If "Starting the server.\n" is being buffered and doesn't make it to the pipe, there is nothing you can do on the reader's side.

So, try adding fflush(stdout) after printf("Starting the server.\n").

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.