read a process output with subprocess.Popen

Ashok Prabhu ashokprabhuv at
Thu Feb 4 13:28:20 CET 2010


I m trying a read the output of a process which is running
continuously with subprocess.Popen. However the readline() method
hangs for the process to finish. Please let me know if the following
code can be made to work with subprocess.Popen with threads or queues.
I tried a lot of methods but to no avail. It would be great if someone
can make it work.

import subprocess

p1 = subprocess.Popen('tail -f /var/log/
p2 = subprocess.Popen('grep

while 1:
    line = p2.stdout.readline()
    print line


More information about the Python-list mailing list