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

Jim Vickroy Jim.Vickroy at noaa.gov
Fri Jun 25 11:41:56 EDT 2004


You could try using sys.stdout.flush(), after print statements in
sometask.py.  If that does not help, you might look at the mmap module.  If
mmap does not meet your needs, you may have to try other forms of message
passing to get the "realtime" performance you desire.

-----Original Message-----
From: python-win32-bounces+jim.vickroy=noaa.gov at python.org
[mailto:python-win32-bounces+jim.vickroy=noaa.gov at python.org]On Behalf
Of byo
Sent: Saturday, June 19, 2004 6:36 PM
To: python-win32 at python.org
Subject: [python-win32] How to monitor the stdout/stderr of somecmd.exe


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.

Newbie


#
# 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





_______________________________________________
Python-win32 mailing list
Python-win32 at python.org
http://mail.python.org/mailman/listinfo/python-win32




More information about the Python-win32 mailing list