#!/usr/bin/perl use strict; use IO::Handle; autoflush STDOUT 1; # had to do this, even tho Open3 doc said it would be done already while (<>) { chomp; print "line $. to STDOUT: $_\n"; warn "mesg $. to STDERR\n"; } #### #!/usr/bin/perl use strict; use IPC::Open3; my $cmd = "test-child.pl"; my ( $in, $out, $err ); $err = "true"; # any string will do (don't use a number) my $pid = open3( $in, $out, $err, $cmd ); my ( $outlog, $errlog ); for ( 1..3 ) { print $in "data $_\n"; $outlog .= <$out>; $errlog .= <$err>; } close $in; waitpid $pid, 0; print "outlog contained:\n$outlog\n"; print "errlog contained:\n$errlog\n"; __OUTPUT__ outlog contained: line 1 to STDOUT: data 1 line 2 to STDOUT: data 2 line 3 to STDOUT: data 3 errlog contained: mesg 1 to STDERR mesg 2 to STDERR mesg 3 to STDERR