Dialog with a process via subprocess.Popen blocks forever
bayer.justin at googlemail.com
bayer.justin at googlemail.com
Wed Feb 28 16:27:43 EST 2007
Hi,
I am trying to communicate with a subprocess via the subprocess
module. Consider the following example:
>>> from subprocess import Popen, PIPE
>>> Popen("""python -c 'input("hey")'""", shell=True)
<subprocess.Popen object at 0x729f0>
>>> hey
Here hey is immediately print to stdout of my interpreter, I did not
type in the "hey". But I want to read from the output into a string,
so I do
>>> x = Popen("""python -c 'input("hey\n")'""", shell=True, stdout=PIPE, bufsize=2**10)
>>> x.stdout.read(1)
# blocks forever
Is it possible to read to and write to the std streams of a
subprocess? What am I doing wrong?
Regards,
-Justin
More information about the Python-list
mailing list