using subprocess for non-terminating command

Phoe6 orsenthil at
Wed Jul 4 13:38:38 CEST 2007

Hi all,
Consider this scenario, where in I need to use subprocess to execute a
command like 'ping' which will have a continuous non-
terminating output in Linux.

# code
>>>import subprocess
>>>process = subprocess.Popen('ping', shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

>>>print # returns pid
>>>print process.poll() # returns None!!! this is strange.

# This hangs at this point.
How should I handle these kind of commands (ping with
subprocess module. I am using subprocess, instead of os.system because
at anypoint in time, I need access to stdout and stderr of execution.


More information about the Python-list mailing list