in reply to Catching timeout for Net::Telnet

eval { $t = Net::Telnet->new(...); $t->open(...); # and so on }; warn $@ if $@;
$@ holds any error message the stuff inside the eval {} might have died with.

Replies are listed 'Best First'.
Re: Re: Catching timeout for Net::Telnet
by HeffaK (Initiate) on May 09, 2001 at 22:41 UTC
    It did not work the way I used it...it still just dies.
    Any more ideas...
    heres the modified code..
        use Net::Telnet (); 
     eval {
        $t = Net::Telnet ->new(Timeout => 10,
    			  Prompt => '/.*# $/');
    };
    warn $@ if $@;    
    $t->open("10.0.0.$num") || die "can't telnet to $num\n";
        $t->login('$log','$pwd');
        $t->cmd("cd /home/dir");
    
        @lines = $t->cmd("ps uax");
    ...
    
    Thanks. HeffaK
      Go back and re-read my original post. You need to move all the operations on $t inside the eval {}. It's probably the open or login that's die()ing, not the Net::Telnet->new, anyway.

      If there's a failure at some point, you probably want to give up on the entire telnet session. After all, if the login fails, what's the chance of "cd /home/dir" working? If you put everything in the eval {}, the first one that dies will jump to the end of the eval block, skipping over the other commands.

        That did it... :) Thank you and Thank you again. HeffaK