期望在 Perl 控制台输出脚本
Expect script output at Perl console
我有一个 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
它给了我预期的输出 window -
"Successfully entered the name"
如果出现问题,它会抛出异常或错误消息。
我运行 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 return 代码。
如果我理解正确,要得到你想做的return代码:
system($cmd);
my $ret_code = $?;
从执行中获取 STDOUT 输出:
my @out = `$cmd`;
my $ret_code = $?;
我强烈建议在您的代码中使用 strict 和 warnings。
我有一个 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
它给了我预期的输出 window - "Successfully entered the name" 如果出现问题,它会抛出异常或错误消息。
我运行 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 return 代码。
如果我理解正确,要得到你想做的return代码:
system($cmd);
my $ret_code = $?;
从执行中获取 STDOUT 输出:
my @out = `$cmd`;
my $ret_code = $?;
我强烈建议在您的代码中使用 strict 和 warnings。