【发布时间】:2012-08-17 19:41:05
【问题描述】:
在我们的一个模块中,我们检查给定的二进制文件 (varnishd) 是否存在,如果存在,我们会运行其他测试。
为了执行检查,我们使用IPC::Open3,就像这样(为了清楚起见,示例被删除):
perl -MIPC::Open3 -le '
my $binary = "varnishd";
my $pid = IPC::Open3::open3(my($in, $out), undef, $binary, "-V");
waitpid $pid, 0; print $?'
在带有 perl 5.10.1 的 Debian Squeeze 或 Ubuntu Natty 下,如果在系统上找不到 varnishd,这将为我打印 65280。
如果您将$binary 更改为perl,则(正确)打印0。
但是,对于 Ubuntu Precise 和 perl 5.14.2,这不再以相同的方式工作,并产生以下结果:
$ perl -MIPC::Open3 -le '
my $binary = "varnishd";
my $pid = IPC::Open3::open3(my($in, $out), undef, $binary, "-V");
waitpid $pid, 0; print $?'
open3: exec of varnishd -V failed at -e line1
当我将$binary 更改为存在的东西时,例如perl,它会正常工作并打印0。
$ perl -MIPC::Open3 -le '
my $binary = "perl";
my $pid = IPC::Open3::open3(my($in, $out), undef, $binary, "-V");
waitpid $pid, 0; print $?'
0
阅读其他问题和答案,看起来我想研究IPC::Run,但实际上我想:
- 了解这种行为差异
- 尽可能避免任何依赖
编辑:忘了提到这些东西是在 chroot 环境下运行的,包括 Squeeze 和 Precise 系统,如果这完全相关的话(例如/dev 文件系统差异?)。
【问题讨论】: