Get partial stdout and stderr from Popen that works indefinitely

Possible duplicate:
Bypassing subprocess output buffering with popen in C or Python

I am creating a wrapper around the server's cmd line script which should run indefinitely. What I need to do is get the current value without waiting for the subprocess to finish.

I mean if I run the following everything works fine:

ls = Popen(["ls"], stdout=PIPE)
output = ls.stdout.read()

      

But if I do the same with an unlimited program:

server = Popen(["python","-m","SimpleHTTPServer"], stdout=PIPE)
output = server.stdout.read()

      

He will not return...

Update: even

 output = server.stdout.read(1) 

      

hangs ...

Do you know if there is a way to capture partial output from Popen (or a similar streaming implementation) in an OS independent way?

+2


source to share


1 answer


I would assume read () returns all content? If you are reading a fixed size snippet in a loop, you can get better results.



-1


source







All Articles