【发布时间】:2014-05-12 02:23:36
【问题描述】:
我正在运行以下脚本:
#!/usr/local/bin/perl -w
use strict;
use warnings;
use Net::SSH::Expect;
my $ssh = Net::SSH::Expect->new(host=>"xxx.xxx.xxx.xxx",password=>"xxxxxxx", user=>"root" ,timeout=>3 );
$ssh->login();
$ssh->exec("stty -echo");
print "Connection Established\n";
my ($out) = $ssh->exec("rpm -ivh xxx");
print "\n\nOUTPUT: $out\n";
#$ssh->send("echo $?");
($out) = ($ssh->get_expect())->exitstatus();
print "\n\nEXIT STATUS: $out\n";
运行这个,我无法获得我执行的“rpm -ivh ...”命令的退出状态。
我是 Perl 新手,请帮帮我。
【问题讨论】:
-
为什么要在 ($out) 周围加上括号?文档没有这些。 (metacpan.org/release/Net-SSH-Expect) 此外,如果您有“使用警告”,您可以删除第一行中的 -w 标志。
-
@davewood。确实,您应该尝试
$out = $ssh->exec("rpm -ivh xxx");...但这不会解决您对$?的渴望,也不会解决远程提示和/或prompt_command 的潜在问题。