Net::Telnet and waitfor context problem

J

Jim Mozley

I have seen a problem using Net::telnet that I can work around but cannot
explain.

I use the following for wait for a particular pattern match in the input
stream:

$session->waitfor(Match => '/mymatch/',
Errmode => 'return')
or die "cannot match it", $session->lastline;

This is as shown in an example in the module documentation.

The only way I can get this to actually die is to use the default errmode
(which is die). If I use error mode return or my own error handling
subroutine the test is always true even when it should not (I have used
input_log and dump_log to check the input).

The way I can get round this is to use a test in a list context e.g.

($prematch, $match) = $session->waitfor(Match => '/Password:/',
Errmode => "return");
if ( $match ) {
print "found it\n";
} else {
print "did not find it\n";
}

or even

($ok) = $session->waitfor(Match => '/Password:/',
Errmode => "return");
if ( $ok ) {
etc.

What I was originally trying to do was something along the lines of:

unless ( $result = $session->waitfor('/match/') ) {
print "failed to match \"match\" before timeout";
etc.
}

or even

unless ( $session->waitfor('/match/') ) {
etc.

and as a result of trying to work out why this was not working for me
discovered the "context problem". Can anyone explain what I'm doing wrong?
Rather than work on a larger program (where I discovered the problem) I have
replicated this in a much smaller script where I have aimed to follow the
module examples as near as possible, but I still see the issue.

Regards,

Jim
 
A

Anno Siegel

Jim Mozley said:
I have seen a problem using Net::telnet that I can work around but cannot
explain.

I use the following for wait for a particular pattern match in the input
stream:

$session->waitfor(Match => '/mymatch/',
Errmode => 'return')
or die "cannot match it", $session->lastline;

This is as shown in an example in the module documentation.

The only way I can get this to actually die is to use the default errmode
(which is die). If I use error mode return or my own error handling
subroutine the test is always true even when it should not (I have used
input_log and dump_log to check the input).

I cannot reproduce this. This

use Net::Telnet;
my $t = Net::Telnet->new( 'localhost') or die;
$t->waitfor( Match => '/mymatch/', Errmode => 'return') or
die "timeout";

dies with "timeout" every time. Perl 5.8.0, Net::Telnet 3.03

Anno
 
J

Jim Mozley

I cannot reproduce this. This

use Net::Telnet;
my $t = Net::Telnet->new( 'localhost') or die;
$t->waitfor( Match => '/mymatch/', Errmode => 'return') or
die "timeout";

dies with "timeout" every time. Perl 5.8.0, Net::Telnet 3.03

Anno

Thanks for trying to replicate this.

I'm using Perl 5.8 with Net::Telnet 3.03 as well on Solaris 8. I can
replicate the problem reliably :-( i.e. if I have /willnevermatch/ instead
of /somematch/ the script still won't die.

Jim
 
A

Anno Siegel

Jim Mozley said:
Thanks for trying to replicate this.

I'm using Perl 5.8 with Net::Telnet 3.03 as well on Solaris 8. I can
replicate the problem reliably :-( i.e. if I have /willnevermatch/ instead
of /somematch/ the script still won't die.

I ran it on Solaris 8 (with Perl 5.6.1 Net::Telnet 3.03) with the
same results (i.e., it behaves). Something weird is going on on your
side.

Anno
 
J

Jim Mozley

I ran it on Solaris 8 (with Perl 5.6.1 Net::Telnet 3.03) with the
same results (i.e., it behaves). Something weird is going on on your
side.

Anno

OK I'll try to look some more. I am using the latest version of
Net::Telnet::Cisco too, I don't know if this would cause me problems.

Jim
 
J

Jim Mozley

mmmmmmmmmm

I also see wierdness now in matching /matchA|matchB/. When neither of these
are present the match is a success as it seems to /matchC/ in one particular
case but not others.

Jim
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top