IPC::Run and hanging pipes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian Hann

    IPC::Run and hanging pipes

    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.
  • Brian Hann

    #2
    Re: IPC::Run and hanging pipes

    Well I ended up modifying it to use scalar refs and pump() and it
    works now. Do pipes just NOT work in mod_perl anymore?

    c0bra@beatdowns quad.com (Brian Hann) wrote in message news:<35aac8f9. 0312081053.558c 6b90@posting.go ogle.com>...[color=blue]
    > 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.[/color]

    Comment

    Working...