StoneLeopard has asked for the wisdom of the Perl Monks concerning the following question:
Hello PerlMonks,
I'm trying to spawn a Perl process via an Expect loop. The idea is that the main program would be sending Perl code to the slave, and have it return stuff on STDOUT, which would be received, parsed and acted upon by the main program. I tried to implement this via Expect, but it seems to be deadlocking. Can someone point out what I'm doing wrong?
I'm using Perl v5.14.1 if that makes a difference.
Thanks much. Pankaj
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"; }] ); } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Running Perl in an Expect loop
by haukex (Archbishop) on Dec 15, 2016 at 07:40 UTC | |
by StoneLeopard (Novice) on Dec 15, 2016 at 13:59 UTC | |
by Corion (Patriarch) on Dec 15, 2016 at 14:04 UTC | |
by StoneLeopard (Novice) on Dec 15, 2016 at 16:43 UTC | |
by haukex (Archbishop) on Dec 15, 2016 at 21:26 UTC | |
Re: Running Perl in an Expect loop
by Corion (Patriarch) on Dec 15, 2016 at 08:27 UTC | |
Re: Running Perl in an Expect loop
by salva (Canon) on Dec 15, 2016 at 07:50 UTC | |
Re: Running Perl in an Expect loop
by StoneLeopard (Novice) on Dec 15, 2016 at 16:46 UTC | |
Re: Running Perl in an Expect loop
by Anonymous Monk on Dec 16, 2016 at 00:05 UTC |
Back to
Seekers of Perl Wisdom