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.