似乎读取<$chan>
给出了空列表,并且它主要发生在延迟较高的网络上的主机上。是否有更强大的与远程主机交互的方式?
use Net::SSH2;
# my $ssh = Net::SSH2->new();
# ...
my $chan = $ssh->channel() or die "no channel\n";
$chan->blocking(1); # even worse with $chan->blocking(0);
$chan->shell();
print $chan "ps -ef\n";
print <$chan>;
编辑:
使用时出错Net::SSH::Any
,
无法在 lib/Net/SSH/Any/Backend/Net_SSH2.pm 第 133 行的未定义值上调用方法“exec”。
sub _capture {
my ($any, $opts, $cmd) = @_;
my $ssh2 = $any->{be_ssh2} or return;
my $channel = $ssh2->channel;
my ($out_fh, $err_fh) = __parse_fh_opts($any, $opts, $channel) or return;
$out_fh and die 'Internal error: $out_fh is not undef';
# vvvvvvvvvvvvvv
$channel->exec($cmd); # <--- LINE 133
# ^^^^^^^^^^^^^^
(__io3($any, $ssh2, $channel, $opts->{stdin_data}, undef, $err_fh || \*STDERR))[0];
}