当我在 perl 中关闭管道时获得巨大的退出状态是什么意思

What does it mean when I get a huge exit status when closing a pipe in perl

我运行一个使用管道的脚本

my $pid = open (OUTPUT, "$my_script") || "";
if (! $pid) {
  die("error");
}
while (<OUTPUT>) {
  print;
}
close (OUTPUT);
my $exit_status = $?>>8;
print "$exit_status";

有时我会得到很长的退出状态:72057594037927935

这是什么意思?这可能是什么原因造成的?

你得到一个很长的数字,因为 $? 的值为 -1。将它右移 8 位会得到你得到的大数字。试试这个:

print -1>>8;

$?-1 因为 close() 函数由于某种原因失败,而不是因为脚本以退出状态 -1.

退出

close() 成功并且脚本以 -1 退出时,$? 的值将不是 -1,而是 $?>>8将是 255,如此处所述:Why is the exit code 255 instead of -1 in Perl?