如何捕获在 perl 脚本中调用另一个 perl 脚本的捕获的退出状态,如果失败,它应该死
how to capture the exit status of capture calling another perl script within a perl script and if it fails it should die
我刚开始在 secure-CRT 上使用 Perl 5.26,我编写了一个 Perl 脚本来捕获对多个 Perl 脚本的调用。
my @secondCommand = capture("perl clientquery.pl -r $cid -l test.log -is $sqlFile");
我想知道如何捕获每个捕获调用的退出状态,如果它失败了,我该如何让原始脚本消失。
IPC::System::Simple provides $EXITVAL
,它通过 capture
和其他函数捕获命令 运行 的退出代码。
The exit value of any command executed by IPC::System::Simple can
always be retrieved from the $IPC::System::Simple::EXITVAL
variable:
This is particularly useful when inspecting results from capture,
which returns the captured text from the command.
use IPC::System::Simple qw(capture $EXITVAL EXIT_ANY);
my @enemies_defeated = capture(EXIT_ANY, "defeat_evil", "/dev/mordor");
print "Program exited with value $EXITVAL\n";
$EXITVAL
will be set to -1 if the command did not exit normally (eg,
being terminated by a signal) or did not start. In this situation an
exception will also be thrown.
我刚开始在 secure-CRT 上使用 Perl 5.26,我编写了一个 Perl 脚本来捕获对多个 Perl 脚本的调用。
my @secondCommand = capture("perl clientquery.pl -r $cid -l test.log -is $sqlFile");
我想知道如何捕获每个捕获调用的退出状态,如果它失败了,我该如何让原始脚本消失。
IPC::System::Simple provides $EXITVAL
,它通过 capture
和其他函数捕获命令 运行 的退出代码。
The exit value of any command executed by IPC::System::Simple can always be retrieved from the
$IPC::System::Simple::EXITVAL
variable:This is particularly useful when inspecting results from capture, which returns the captured text from the command.
use IPC::System::Simple qw(capture $EXITVAL EXIT_ANY); my @enemies_defeated = capture(EXIT_ANY, "defeat_evil", "/dev/mordor"); print "Program exited with value $EXITVAL\n";
$EXITVAL
will be set to -1 if the command did not exit normally (eg, being terminated by a signal) or did not start. In this situation an exception will also be thrown.