Running an interactive subprocess with Popen
Eric_Dexter at msn.com
Fri Apr 10 14:27:08 CEST 2009
On Apr 10, 2:56 am, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
> David Liang schrieb:
> > Hello,
> > Sorry for the newbie question. How do I run a program that could
> > block, waiting for user input, using subprocess.Popen? For example,
> > from subprocess import *
> > def foo():
> > a = Popen(['python'] ...)
> > I want to be able to get input from the user and send input to the
> > subprocess, printing stdout and stderr as data becomes available, then
> > return once the subprocess exits. Is it possible to send to the
> > subprocess keyboard interrupts, EOF, and such?
> > I tried doing stdout=PIPE, stderr=PIPE, stdin=PIPE. I tried using
> > communicate(), but could only call it once; subsequent calls raised
> > "ValueError: I/O operation on closed file."
> > And both a.stdout.read() and a.stderr.read() blocked the program. Any
> > help would be much appreciated.
> Use pexpect, which emulates a pseudo-terminal speaking with the subprocess.
> Diez- Hide quoted text -
> - Show quoted text -
I am not sure about that particular issue put I did manage to get it
working with windows in the dex tracker project.. you would have to
search the files or something to figure out where.. when you are
looking at examples it does matter wich operating system you are using
at least for python 2.5
More information about the Python-list