I am attempting to write an application that uses the expect binary to
get info off a telnet session. At first this app was written in
mod_perl under perl 5.005_03 using Expect.pm but we're moving it to
5.6.1 to take advantage of custom security and authentication and
Expect no longer works (similar to the IPC::Open2(3) problems under
mod_perl).
I am in the process of making the code use IPC::Run to call the expect
binary and use pipes to read and write data multiple times during a
session but I am having a problem where the read pipe just hangs, no
output and it never ever comes out of it unless I add a timeout. This
is on Solaris 8. Here is the example code:
#!/usr/bin/perl -w
use IPC::Run qw( start pump finish timeout run );
local(*Reader, *Writer, *ERR);
my @expect = qw( expect - );
my $h = start
\@expect,
'<pipe', \*Writer,
'>pipe', \*Reader,
'2>pipe', \*ERR, $t = timeout( 10 )
or die "expect returned $?" ;
warn "Starting first write\n";
print Writer qq~
exp_internal 1;
set timout 30\;
spawn telnet system
sleep 2
puts "NEXT"
~;
while (<Reader>) { last if /NEXT/; warn "READ\n"; print; }
warn "1\n";
It never gets past the while loop and it never puts out the READ warn
or any data either. I have tried moving this to use readline() in
both scalar and list context with the same results. Is there ANY way
to figure out why this is happening or to get data come back? I had
luck with IPC::Open2 but obviously I can't use that anymore under
mod_perl.