get text from rogramms runn by subprocess.Popen immediatetly

Rüdiger Ranft _rdi_ at
Thu Apr 16 13:12:36 CEST 2009

Hi all,

I need to call some programms and catch their stdout and stderr streams.
While the Popen class from subprocess handles the call, I get the
results of the programm not until the programm finishes. Since the
output of the programm is used to generate a progress indicator, I need
a way to acces the values written to stdout/stderr as fast as possible.

Beneath is a test which shows what I did


----8<-------8<-------8<-- iodummy.cpp -8<-------8<---
#include <iostream>
#include <unistd.h>

int main()
        for( int i = 0; i < 10; i++ )
                std::cerr << i << std::endl;

from subprocess import Popen, PIPE
from time import sleep

p = Popen('./iodummy',stdin=PIPE, stdout=PIPE, stderr=PIPE)
# now I expect '0\n1\n' in stderr, but read() blocks until
# the end of iodummy.

GPG encrypted mails preferred.
GPG verschlüsselte Mails bevorzugt.
---> Seite 20 <----

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 914 bytes
Desc: OpenPGP digital signature
URL: <>

More information about the Python-list mailing list