use Net::SSH::Perl::Constants qw( SSH_SMSG_STDERR_DATA SSH_CMSG_STDIN_DATA); #### #!/usr/bin/perl use strict; use warnings; use Net::SSH::Perl; use Net::SSH::Perl::Constants qw( SSH_SMSG_STDERR_DATA SSH_CMSG_STDIN_DATA ); my $host = 'localhost'; my $username = 'user'; my $password = 'password'; my $cmd1 = 'whereis perl && perl -V'; my $ssh = Net::SSH::Perl->new( $host, protocol => 2, 1, debug => 1, ); $ssh->login( $username, $password ); $ssh->register_handler( SSH_SMSG_STDERR_DATA, sub{ my ( $ssh, $packet ) = @_; my $str = $packet->get_str; if ( $str =~ /Password/ ) { $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA); $packet->put_str($password); $packet->send; } } ); my ($stdout, $stderr, $exit) = $ssh->cmd($cmd1); print $stdout, "\n";