En Wed, 28 Feb 2007 18:27:43 -0300, <[EMAIL PROTECTED]> escribió: > 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 Blocks, or is the child process waiting for you to input something in response?
> Is it possible to read to and write to the std streams of a > subprocess? What am I doing wrong? This works for me on Windows XP. Note that I'm using a tuple with arguments, and raw_input instead of input (just to avoid a traceback on stderr) py> x=Popen(("python", "-c", "raw_input('hey')"), shell=True, stdout=PIPE) py> x.stdout.read(1) 1234 'h' py> x.stdout.read() 'ey' I typed that 1234 (response to raw_input). You may need to use python -u, or redirect stderr too, but what your real problem is? -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list