Perl - $?在 Windows 2008 64 位上,-1 返回代码显示 0

标签 perl system

使用草莓 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/

相关文章:

perl - 如何更改属性类型? (珀尔哞)

perl - 支持自动激活文件句柄作为 Perl XS 例程的参数

perl - 如何将 Perl 代码从 mod_perl 移植到 FastCGI?

c - Linux Mint 中的函数 fork

eclipse - 最终启动顺序错误 - STM32L476 的 Eclipse System Workbench 调试

PERL 如何将本地时间格式转换为 unixtime

Perl 模块获取网站的所有页面?

c - 系统调用 open() 似乎在创建文件时随机设置文件权限

c - 如何使用 write 系统调用

sockets - 无法打开与系统消息总线的连接 : Failed to connect to socket/var/run/dbus/system_bus_socket