Iam using Net::Telnet to issue some commands to a remote server. I have no problems in connecting to the server and executing the commands. I always get a return status of '1' from the cmd() even if the command fails. How should I check for the return status of the cmd() in Net::Telnet module.
use strict;
use warnings;
my $t = new Net::Telnet (
Prompt => '/.*\d+\s*%>.*$/',
Timeout => 15,
);
my ( $hostname, $username, $passwd ) = ( 'xxx', 'xxx', 'xxx' );
$t->open($hostname);
$t->login($username, $passwd) or die "Cannot connect to the server";
print "Connected to $hostname as '$username'\n";
# This does not seem to work
#$t->errmode(sub { warn @_ } );
my ( @output, $output );
# Change to some directory that is not there
# It gives the output properly with error messages if any
@output = $t->cmd ("/bin/cd not_there");
print "@output";
# always returns 1
$output = $t->cmd ("/bin/cd not_there");
print $output;
Update :
Can I use
echo $? after every command to know the status of the commands. Will Net::Telnet do anything in between the actual command and the
echo $? to change
$?. Please advise.
Hope Iam clear
-T
use perl; use strict;