Dialog with a process via subprocess.Popen blocks forever

bayer.justin at googlemail.com bayer.justin at googlemail.com
Thu Mar 1 12:42:00 EST 2007


Okay, here is what I want to do:

I have a C Program that I have the source for and want to hook with
python into that. What I want to do is: run the C program as a
subprocess.
The C programm gets its "commands" from its stdin and sends its state
to stdout. Thus I have some kind of dialog over stdin.

So, once I start the C Program from the shell, I immediately get its
output in my terminal. If I start it from a subprocess in python and
use python's sys.stdin/sys.stdout as the subprocess' stdout/stdin I
also get it immediately.

BUT If I use PIPE for both (so I can .write() on the stdin and .read()
from the subprocess' stdout stream (better: file descriptor)) reading
from the subprocess stdout blocks forever. If I write something onto
the subprocess' stdin that causes it to somehow proceed, I can read
from its stdout.

Thus a useful dialogue is not possible.

Regards,
-Justin






More information about the Python-list mailing list