IPC::Run and hanging pipes

Discussion in 'Perl' started by Brian Hann, Dec 8, 2003.

  1. Brian Hann

    Brian Hann Guest

    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, Dec 8, 2003
    #1
    1. Advertising

  2. Brian Hann

    Brian Hann Guest

    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?

    (Brian Hann) wrote in message news:<>...
    > 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, Dec 11, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. piyush
    Replies:
    0
    Views:
    1,839
    piyush
    Jul 14, 2004
  2. piyush
    Replies:
    1
    Views:
    3,150
    John Harrison
    Jul 14, 2004
  3. piyush
    Replies:
    0
    Views:
    451
    piyush
    Jul 14, 2004
  4. Swaroop C H

    Pipes of binaries - IPC::Run

    Swaroop C H, May 11, 2005, in forum: Python
    Replies:
    1
    Views:
    353
    Peter Hansen
    May 11, 2005
  5. Replies:
    17
    Views:
    4,696
    CBFalconer
    Jan 13, 2009
Loading...

Share This Page