For those who fighted with Net::SSH::W32Perl that is hanging, here is a workaround, on Windows only (thx to
this perlmonk's person):
use Net::SSH::W32Perl;
use Net::SSH::Perl;
use Net::SSH::Perl::Constants qw( :protocol);
...
if ($^O eq 'MSWin32') {
no warnings;
*Net::SSH::Perl::set_protocol = sub {
my $ssh = shift;
my $proto = shift;
$ssh->{use_protocol} = $proto;
my ($package, $filename, $line) = caller;
my $proto_class = join '::', $package,
($proto == PROTOCOL_SSH2 ? "SSH2" : "SSH1");
if ($proto_class =~ /Net::SSH::Perl/) {
# We are on Windows, and we explicitely use Net::SSH::W32Perl
$proto_class =~ s/Net::SSH::Perl/Net::SSH::W32Perl/g;
}
(my $lib = $proto_class . ".pm") =~ s!::!/!g;
require $lib;
bless $ssh, $proto_class;
$ssh->debug($proto_class->version_string);
$ssh->_proto_init;
};
}
# Set $HOME (if not set), to avoid another Net::SSH::Perl bug...
$ENV{HOME} = "C:\\" if(! defined($ENV{HOME}) || ! $ENV{HOME});
…
my $ssh = new Net::SSH::W32Perl($host, options => ["ForwardX11 yes"]);
$ssh->login($login, $password);
my ($out,$err,$ex) = $ssh->cmd($cmd);