in reply to Re: Pipe, fork, exec and red-hot pokers.
in thread Pipe, fork, exec and red-hot pokers.

This may be a long shot, but *how* are you reading that output? are you using the diamond operator, or are you reading via select(IO::Select) + read/sysread ? It may not have anything to do with your problem at all, but who knows...

FWIW, something like the following works for me

# note: this code will go into infinite loop # and is not a particularly good piece of code... use IO::Handle; use IO::Select; my( $readfh, $writefh ) = ( IO::Handle->new(), IO::Handle->new() ); pipe( $readfh, $writefh ); if( my $pid = fork() ) { $writefh->close(); my $select = IO::Select->new( $readfh ); my $buf; while( 1 ) { if( $select->can_read( 1 ) ) { if( read( $readfh, $buf, 4096, 0 ) ) { print "got '$buf'"; } } } } else { $readfh->close; open( STDOUT, sprintf( '>&%d', $writefh->fileno ) ); STDOUT->autoflush(1); exec( 'find', '/usr/local/lib/perl5' ); }

Replies are listed 'Best First'.
Re: Re: Re: Pipe, fork, exec and red-hot pokers.
by hagus (Monk) on Apr 09, 2002 at 00:49 UTC
    First, I changed 'read' to 'sysread'. But if the program you are exec()ing is this:
    #!/usr/bin/perl my $i=0; while (1) { print "stdout " . $i++ . "\n"; sleep 1; }
    Then you will find that no output is captured by read. The perl program must set $|=1, which is exactly what I don't want to have to worry about.

    --
    Ash OS durbatulk, ash OS gimbatul,
    Ash OS thrakatulk, agh burzum-ishi krimpatul!
    Uzg-Microsoft-ishi amal fauthut burguuli.