using subprocess for non-terminating command
orsenthil at gmail.com
Wed Jul 4 13:38:38 CEST 2007
Consider this scenario, where in I need to use subprocess to execute a
command like 'ping 127.0.0.1' which will have a continuous non-
terminating output in Linux.
>>>process = subprocess.Popen('ping 127.0.0.1', shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>>>print process.pid # returns pid
>>>print process.poll() # returns None!!! this is strange.
# This hangs at this point.
How should I handle these kind of commands (ping 127.0.0.1) 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