it does not work again. Re: help!! getting output from another process line by line, using popen

Lao Coon laocoon at eudoramail.com
Fri Jan 17 09:22:24 EST 2003


*snip*
>> 
>> This has something to do with the way the output is returned here..
>> When you say "for line in handle" read() is called, it waits
>> until everything has been received and then returns it as a list(only
>> once). To fix it explicitly call readline() instead.
>> 
>> HTH
>> Lao
> 
> if you mean that "handle = os.popen(cmd, 'r', 1).readlines()", it wont
> work. it waits till finish running cmd, then go to the "for loop".
> 
> thanks anyway

No i think you misunderstood.. 

Here's the fixed monitor.py

###
import sys, string, os

handle = os.popen("python -u output.py", 'r')

while 1:
	line = handle.readline()
	if line == "": break
	print line,

handle.close()
###

Try this

Lao




More information about the Python-list mailing list