doing my pipe between 2 process

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • elrik

    doing my pipe between 2 process

    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.file no())
    print 'exemple'
    sys.stdout.flus h()

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

    #2
    Re: doing my pipe between 2 process

    elrik wrote:[color=blue]
    > 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.file no())
    > print 'exemple'
    > sys.stdout.flus h()
    >
    > but il doesn't work!
    > How can i make a write AND read file descriptor ?
    > Thanks[/color]

    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).

    Comment

    Working...