Dialog with a process via subprocess.Popen blocks forever
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
.
Relevant Pages
- Re: Dialog with a process via subprocess.Popen blocks forever
... I am trying to communicate with a subprocess via the subprocess ... type in the "hey". ... 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? ... (comp.lang.python) - Re: Chaining programs with pipe
... you do the same thing you would in C. Create a pipe ... then run one program with stdout connected to ... The doc page for subprocess doesn't say what platforms support ... As is typical for Windows, ... (comp.lang.python) - Re: Dialog with a process via subprocess.Popen blocks forever
... from the subprocess' stdout stream (better: file descriptor)) reading ... from the subprocess stdout blocks forever. ... buffer when reading from two pipes. ... (comp.lang.python) - Re: capture stdout and stderror from within a Windows Service?
... can I capture the stdout and stderr if I launch a subprocess using ... stderr filedescriptors for the child process. ... or nonexistant file descriptors of the parent. ... (comp.lang.python) - Re: capture stdout and stderror from within a Windows Service?
... I think you need to run the .exe from your .py using the subprocess module's commands and hook in at that time to stdin, stdout, .... ... get the fn and use check_callto see if .exe has something to say. ... How you would redirect I/O in an arbitrary already running program in Windows is a good question. ... (comp.lang.python) |
|