无法使用Net :: SSH2从远程设备获取输出

时间:2017-03-17 13:35:31

标签: perl ssh blocking

我正在尝试通过Net :: SSH2连接到远程设备。如果我使用$ channel-> blocking(0)方法,那么即使连接和身份验证成功,我也无法从设备获得任何输出。如果我不使用$ channel-> blocking(0),那么我得到输出但是提示会继续闪烁,从某种意义上说程序会卡住。

代码

use Net::SSH2;
use strict;

$ssh = Net::SSH2->new()

$ssh->connect('xx.xx.xx.xx'))

$ssh->auth(username => 'xxxx', password => 'xxxx'))

my  $channel = $ssh->channel() or do { print" [LOG ERROR]: Failed to create channel. Exiting ...\n"};

$channel->blocking(0);

$channel->shell() ;

print $channel "show status \n";

while(<$channel>)
  {
     print $_;
  }

$channel->close(); 

$ssh->disconnect();

有人可以帮忙吗。

1 个答案:

答案 0 :(得分:0)

也许debug可以帮助您排除故障。如果没有特别原因您使用command CC=$(DEVELOPER_DIR=<whatever> xcrun -f --sdk macosx clang)尝试将其替换为shell。您可以采用此example

exec也很有用。

相关问题