使用草莓 Perl 5.12.3
手动运行:
E:\informatica\tools>infacmd isp ping -sn tt -re 0
[ICMD_10033] Command [ping] failed with error [[INFACMD_10053] Service [tt] Domain [dmt3-9-dom-poc] has failed to ping back.].
E:\informatica\tools>echo %ERRORLEVEL%
-1
当我通过 Perl 的“系统”运行相同的命令时,$?显示 0。Perl 代码:
use strict;
use warnings;
my $cmd = system("infacmd isp ping -sn tt -re 0");
if ($? == -1) {
print "failed to execute: $!\n";
}
elsif ($? & 127) {
printf "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without';
}
else {
printf "child exited with value %d\n", $? >> 8;
}
输出:
[ICMD_10033] Command [ping] failed with error [[INFACMD_10053] Service [tt] Domain [dmt3-9-dom-poc] has failed to ping back.].
child exited with value 0
在 Windows 2003 32 位和 ActiveState Perl 5.8.8 上同样显示正确的结果。
最佳答案
使用 ${^CHILD_ERROR_NATIVE}
可能比模拟 unix 的进程状态结构更幸运。
关于Perl - $?在 Windows 2008 64 位上,-1 返回代码显示 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6170503/