in reply to Timeout parameter for Net::Telnet under Windows

Well, this is silly. Net::Telnet wants to time out with alarm(), although IO::Socket has a better method — non-blocking connect — that ought to work on Windows, too.

Perhaps you could try to outsmart the Net::Telnet? Create your object sans Host/Timeout; connect with open() instead. Then slip a sneaky $t->SUPER::timeout(1); before the open. Just an idea...

Replies are listed 'Best First'.
Re^2: Timeout parameter for Net::Telnet under Windows
by SwaJime (Scribe) on Jan 22, 2016 at 18:14 UTC

    Ok, so I tried this. But I don't know exactly how to pull it off.

    I took the Host out of the new() constructor so that the constructor would not call open(), and added these lines of code:

    289 t->{Host} = $host; 290 t->SUPER::timeout(1); 291 t->open();
    I get this error:
    Error: Not a HASH reference at line test.pl line 289.

      I haven't tried this on Windows yet so your mileage may vary.

      #!/bin/env perl use strict; use warnings; use Net::Telnet; my $host = '192.168.130.112'; # valid host that is offline my $port = 10001; print "DEBUG 1\n"; my $t = new Net::Telnet ( Port => $port, Prompt => '/Escape character is.+\n/', Rs => ' ', Ors => '', Binmode => 1, Telnetmode => 1, Errmode => 'return'); print "DEBUG 2\n"; if (!$t) { die "Failed to create telnet object\n"; } $t->open(Host => $host, Timeout => 1) or die "Failed to create telnet session\n";
        I tried this. The results are the same. It is taking 20 to 30 seconds before it times out.