using subprocess for non-terminating command
orsenthil at users.sourceforge.net
Wed Jul 4 21:29:31 CEST 2007
* Jerry Hill <malaclypse2 at gmail.com> [2007-07-04 11:23:33]:
> That's because you tied stdin to a pipe in your Popen call, but then
> tried to read from stdout. Try this instead:
My mistake. I had just 'typed' the command in the mail itself and forgot to
include the stdin, stdout, and stderr and mentioned it as hung based on some
> >>> process = subprocess.Popen("ping -c 10 127.0.0.1",
> stdout=subprocess.PIPE, shell=True)
> >>> process.stdout.readlines()
I tried it again and found that giving the -c 10 returns a well defined
Only when the program has executed and the output available, subprocess can
read through PIPE's stdout it seems ( not at any other time).
With killing, I loose the output.
>>> process = subprocess.Popen('ping 10 127.0.0.1', stdin=subprocess.PIPE,
>>> import os
>>> import signal
>>> # required output is lost!
More information about the Python-list