in reply to Get live output of exec
Here is a simple example( not using IO::Pipe ).
#!/usr/bin/perl use warnings; use strict; use IO::Handle; $|++; pipe( PARENT_READER, CHILD_WRITER ); pipe( CHILD_READER, PARENT_WRITER ); PARENT_WRITER->autoflush(1); CHILD_WRITER->autoflush(1); my $pid; if ( $pid = fork() ) { close(CHILD_READER); close(CHILD_WRITER); my $buffer; print PARENT_WRITER 1; while (1) { sysread( PARENT_READER, $buffer, 100 ); print "parent revd: $buffer, and reply with ", $buffer + 1, "\ +n"; sleep(1); print PARENT_WRITER $buffer + 1; } } else { close(PARENT_READER); close(PARENT_WRITER); my $buffer; while (1) { sysread( CHILD_READER, $buffer, 1000 ); print "child revd: $buffer, and reply with ", $buffer + 1, "\n +"; sleep(1); print CHILD_WRITER $buffer + 1; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Get live output of exec
by LanX (Saint) on Mar 04, 2014 at 13:35 UTC | |
by kennethk (Abbot) on Mar 04, 2014 at 15:33 UTC |