sksridevnair has asked for the wisdom of the Perl Monks concerning the following question:

Hai, I have to execute a command through telnet and I am using Net::Telnet module.The command takes a varied amount of time for completion(depending on the data it has to retrieve).I have tried to disable timeout in telnet using the undefined value(undef) but could not succeed. Can any one help? An example code which I am using to open a connection:
$xTelnet = new Net::Telnet (Timeout => 'undef', Prompt =>'/[\%\#\>\$] $/',);
Thank you, Sridev

edited: 17 Jun 2002 by jeffa - added code tags

Replies are listed 'Best First'.
Re: How to disable timeout in Net::Telnet
by Marza (Vicar) on Jun 17, 2002 at 18:22 UTC

    Try it without the single quotes; as in

    $xTelnet = new Net::Telnet (Timeout => undef, Prompt =>'/\%\#\>\$ $/') +;
      Even without single quotes it is not working. My code is like this:
      $xTelnet = new Net::Telnet (Timeout => undef, Errmode => sub {$sMsg = $xTelnet->errmsg(); $sLog = $xTelnet->dump_log(); $sLastMsg = $xTelnet->lastline(); print STDERR "\nERROR_MSG::$sMsg"; print STDERR "\nLOG_MSG::$sLog"; print STDERR "\nLAST_MSG::$sLastMsg"; return; }, Prompt =>'/[\%\#\>\$] $/',);

      edited: 17 Jun 2002 by jeffa - added code tags

Re: How to disable timeout in Net::Telnet
by Rex(Wrecks) (Curate) on Jun 17, 2002 at 22:04 UTC
    Update 2: Ok, I just tried the following, where "dir" will hang at a "more" prompt:
    use Net::Telnet ; my $telnetSession = new Net::Telnet (Timeout => undef, Prompt => '/\>/ +') ; $telnetSession->open("10.0.0.1") ; $telnetSession->login("administrator", "password") ; my @DirInfo = $telnetSession->cmd("dir") ;
    The only thing changed from the code I ran is the IP and the User and pass and it is still hung (5+ minutes). This is on Win2K with ActiveState's v5.6.1 build 629.

    So it looks like the desired behavior is working for me.

    Update 3: Ah, it just timed out...from the other side! Are you sure it's Net::Telnet and not the responder that is timing it out? (and yes my sniffer confirmed it :)

    I looked through the timout methods in the module, and it appears to require a numeric timout, undef is treated like you did not specify anything and hence defaults to 10 seconds.

    My other suggestion is to crank the timout up to the max seconds you could ever imagine the data retrieval to take, add a 1 minute buffer, and use that.

    I would also recomend setting the timeout right before the command and then resetting it right after.

    Update: A second look tells me that undef should be valid! I'm looking into this further.

    "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!

      Which module? Unless the doc is wrong this is what was said from the Net-Telnet 3.02. Section on timeout

      If $secs is 0 then time-out occurs if the data cannot be immediately read or written. Use the undefined value to turn off timing-out.

      However, maximizing the seconds would have been my suggestion if I saw this in time ;)

      Yes, Ok I got a bit now. It is not the Net::Telnet, its the server that is timing-out the telnet session before the process is completed.How do I over come this problem of server timing out?Any help? Thank you very much. Sridev