【发布时间】:2015-02-26 03:37:40
【问题描述】:
我有一个 exp 脚本 -script.exp 来输入名称和密码。它调用 test.sh 文件,如下所示。
set timeout -1
spawn ./test.sh -create
match_max 100000
expect -exact "Enter the name: "
send -- "abcd\r"
expect -exact "\r
Please confirm password: "
send -- "xxy\r"
expect -exact "\r
expect eof
它在期望窗口给我一个输出 - “成功输入姓名” 如果出现问题,它会引发异常或错误消息。
我在 Perl 文件中运行这个期望脚本——如下所示
$cmd="expect script.exp";
system($cmd);
$outputfromexp=?
运行脚本后,我需要在 Perl 控制台中输出 exp 的失败或通过状态。
我该怎么做?请帮帮我。
我尝试按照我的 Perl 脚本中的建议进行调用--
use strict;
use warnings;
sub sysrun {
my ($command) ="expect script.exp";
my $ret_code;
$ret_code = system("$command");
if ( $ret_code == 0 ) {
# Job suceeded
$ret_code = 1;
}
else {
# Job Failed
$ret_code = 0;
}
return ($ret_code);
}
my $ret_code=sysrun();
print "reuturmsfg- $ret_code\n";
但它什么也没打印——只是 reuturmsfg-。
我做了更改-
my $ret_code=sysrun();
它给了我 0 和 1 的返回码。
【问题讨论】:
-
Always
use strict和use warnings在 every Perl 程序的顶部。 从不使用 & 符号&调用 Perl 子例程。 -
我使用了严格和警告。并删除 & 即使 $ret_code 没有输出