[python-win32] How to monitor the stdout/stderr of somecmd.exe

byo byo at myrealbox.com
Thu Jun 17 21:08:57 EDT 2004


I'd like to write a python program that will monitor the stdout/stderr 
of an executable (somecmd.exe) running on W2K. (simulated by sometask.py 
as below) I'm trying to react to it's output *as it is happening* (eg. 
thru monitor_sometask.py) by using win32pipe, but I find that I'm only 
getting the pipe's output too long after the fact. How can I monitor the 
output of somecmd.exe as it happens ? 

Thanks in advance.


#
# monitor_sometask.py
#
import win32pipe
import time
f = win32pipe.popen("c:\python23\python sometask.py", 'r')
while 1:
    aLine = f.readline()
    if not aLine: break
    print 'now:', time.asctime(), '   process :', aLine
    # do something with aLine here
f.close()


#
# sometask.py
#
import time
for i in range(0,3):
    print time.asctime()
    time.sleep(2)



#
# sample output
#
now: Fri Jun 18 10:22:43 2004    process : Fri Jun 18 10:22:36 2004
now: Fri Jun 18 10:22:43 2004    process : Fri Jun 18 10:22:38 2004
now: Fri Jun 18 10:22:43 2004    process : Fri Jun 18 10:22:40 2004








More information about the Python-win32 mailing list