using subprocess for non-terminating command

O.R.Senthil Kumaran orsenthil at
Wed Jul 4 21:29:31 CEST 2007

* Jerry Hill <malaclypse2 at> [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",
>  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', stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,shell=True)
>>> import os
>>> import signal
>>> os.kill(,signal.SIGINT)
>>> # required output is lost!

O.R.Senthil Kumaran

More information about the Python-list mailing list