Dialog with a process via subprocess.Popen blocks forever
george.trojan at noaa.gov
Thu Mar 1 18:54:44 CET 2007
bayer.justin at googlemail.com wrote:
> 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
> 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.
Have you considered using pexpect: http://pexpect.sourceforge.net/ ?
More information about the Python-list