I hope this is a simple python question.
When I try the following in the python interpreter:
>>> import process
>>> def test(cmd):
... p = subprocess.Popen(cmd)
...
>>> test(['ls', '-l'])
It will run the ls -l
, but I need to hit "return" to get a new >>> prompt.
However, when I try the following:
>>> import process
>>> def test(cmd):
... p = subprocess.Popen(cmd)
... p.wait()
...
>>> test(['ls', '-l'])
Then the ls -l
will be run with a >>> prompt immediately present.
One other variation:
>>> import process
>>> def test(cmd):
... p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
...
>>> test(['ls', '-l'])
This will give me an immediate new prompt.
The last example is closest to what I want. My goal is to launch a child process, wait for it to finish and then use its stdout in my parent process by referring to p.stdout
while letting stderr just print to wherever it would otherwise.
Right now in my actual application, the last version just hangs at the:
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
with or without a p.wait()
.
Thanks,
Charlie