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;