FAQ
I want catch stdout and stderr of an child process and read them with
the parent process.
It's like popen4 but wihout shell commande.

something like that :

r, w = os.pipe()
input= os.fdopen(w)
pid=os.fork()
if pid: #parent
while 1:
input.read()
else:
os.dup2(w, sys.stdout.fileno())
print 'exemple'
sys.stdout.flush()

but il doesn't work!
How can i make a write AND read file descriptor ?
Thanks

Search Discussions

  • Mark Borgerding at Apr 1, 2004 at 2:54 am

    elrik wrote:
    I want catch stdout and stderr of an child process and read them with
    the parent process.
    It's like popen4 but wihout shell commande.

    something like that :

    r, w = os.pipe()
    input= os.fdopen(w)
    pid=os.fork()
    if pid: #parent
    while 1:
    input.read()
    else:
    os.dup2(w, sys.stdout.fileno())
    print 'exemple'
    sys.stdout.flush()

    but il doesn't work!
    How can i make a write AND read file descriptor ?
    Thanks
    input.read() will read the *entire* file.

    It will not return until the child process closes its stdout, either
    explicitly or by exiting.


    You can use input.readline(). Your parent will still block on the
    child's output. If that's not okay, look at "select" and/or
    non-blocking IO (fcntl and os.O_NONBLOCK flag).

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedMar 29, '04 at 3:51p
activeApr 1, '04 at 2:54a
posts2
users2
websitepython.org

2 users in discussion

Elrik: 1 post Mark Borgerding: 1 post

People

Translate

site design / logo © 2022 Grokbase