Subject: | Bug/improvement Net::SSH2::Cisco |
Date: | Tue, 29 Aug 2017 07:32:14 +0200 |
To: | bug-Net-SSH2-Cisco [...] rt.cpan.org |
From: | Eric Smid <eric [...] amerca.nl> |
Hi Michael,
First I want to thank you for the great work for the Net::SSH2::Cisco
module.
When using this module I found that the output of the cmd sub differed
from the output of the cmd sub of the Net::Telnet::Cisco module.
I ran into two problems:
The cmd sub of Net::Telnet::Cisco returns \n at the end of the line,
while the same devices return \r\n at the and of the line when using
Net::SSH2::Cisco.
I solved this by adding the red lines below, which
my ($lines, $last_prompt);
{
local $self->{errormode} = "return";
#send
$self->put($string . $ors);
#wait
select(undef,undef,undef,$pause); # sleep
#read
($lines, $last_prompt) = $self->waitfor($prompt);
}
# Added by Eric Smid to make output the same as Net::Telnet::Cisco
if ( defined $lines) {
$lines =~ s/\r\n/\n/mg; # Replace \r\n by \n
}
return $self->error("command timed-out") if $self->timed_out;
return $self->error($self->errmsg) if $self->errmsg ne "";
The second issue is that the normalize sub puts the \n character at the
end of the line at the beginning of the next line. This is also an issue
with Net::Telnet::Cisco.
I didn't see this behaviour earlier with Net::Telnet::Cisco, because I
normally set terminal length to 0. With Net::Telnet:Cisco _normalize is
only executed when there is a "more: prompt. In Net::SSH2:Cisco it is
always executed.
So:
Line 1\n
Line 2\n
Changes to
Line 1
\n Line 2
\n
I replaced _normalize with this sub. I also use HEX character matching
to make the code more readable.
# Changed by Eric Smid. This Solves the problem where \n is at the
beginning of the next line instead of
# at the end of the current line.
sub _normalize {
foreach (@_) {
1 while s/[^\x08\x7F][\x08\x7F]//g; # Remove combination of non BS
or DEL character followed by BS or DEL character, check again after
removal
s/^.*[\x15]//g; # Remove all characters before
and including NAK character
}
return wantarray ? @_ : join "", @_; # ORS instead?
}
Is it possible to add these improvements to your code at CPAN?
Best Regards,
Eric Smid