Starting a child process and getting its stdout?

cypher543 david at cypherspace.info
Fri Dec 29 10:22:47 EST 2006


Thank you for the examples, but I have tried all of that before. No
matter what I do, my program always hangs while it waits for the
process to exit and then it prints all of the output at once. I've
tried read(), readline(), readlines(), communicate(), etc and it is
always the same.

self.buildPID = subprocess.Popen(["python", "tobeforked.py"], stdout =
subprocess.PIPE)
while self.buildPID.poll() == None:
	output = self.buildPID.stdout.readline()
	self.consoleLogBuffer.insert(self.consoleLogBuffer.get_end_iter(),
output)
	self.consoleLog.scroll_to_mark(self.consoleLogBuffer.get_insert(), 0)

Keep in mind that I'm not required to use subprocess. But I have also
tried os.fork and the pty module. They both produce the exact same
results.

On Dec 29, 3:38 am, Tom Plunket <t... at fancy.org> wrote:
> Tom Plunket wrote:
> >    while p.poll() == None:
> >            data = p.stdout.readline()
> >            if data:
> >                    print data,If you change that print to something more decorated, like,
>
>    print 'process said:', data,
>
> Then it might be more obvious where/how the print statements are getting
> routed.
>
> Keep in mind that readline() will return one line at a time, and that
> line will end with a newline, although the last line you get (at EOF)
> may not have one.
> 
> again, good luck.  Hope this helps,
> -tom!
> 
> --




More information about the Python-list mailing list