use Expect; # create a pipe to slave Perl process my $exp = new Expect; $exp->raw_pty(1); $exp->exp_internal(1); $exp->spawn("/usr/bin/perl") or die "Couldn't start Perl: $!\n"; $exp->log_user(0); $exp->log_stdout(0); # attempting to unbuffer the slave Perl's stdout test_ipc ("select STDOUT; \$| = 1;\n"); test_ipc ("print \"Got this\\n\";\n"); # close the pipe $exp->hard_close(); sub test_ipc { my $line = shift @_; # send command to Perl $exp->send ($line); # may receive any number of lines in return (or none) my $done = 1; while ($done) { $exp->expect (1, [qr"\r\n" => sub { print STDOUT $exp->before(). "\n"; exp_continue; }] , [timeout => sub { $done = 0; print STDOUT "TIMED OUT\n"; }] , [eof => sub { $done = 0; print STDOUT "DONE\n"; }] ); } }