为什么Perl中的system()结果不是我脚本的确切退出代码?
发布时间:2020-12-16 06:09:49 所属栏目:大数据 来源:网络整理
导读:参见英文答案 Why is Perl’s $? returning the wrong value for the exit code of a forked process?????????????????????????????????????2个 我有以下perl脚本(test.pl): my $exit_code = system('./test.py');print $exit_code."n"; 试图从python可执
参见英文答案 >
Why is Perl’s $? returning the wrong value for the exit code of a forked process?????????????????????????????????????2个
我有以下perl脚本(test.pl): my $exit_code = system('./test.py'); print $exit_code."n"; 试图从python可执行文件(test.py)捕获退出代码: #!/bin/env python import sys sys.exit(2) 直接运行python可执行文件返回2,这是我的预期: > ./test.py > echo $? 2 但是,运行perl会返回不同的内容: > perl test.pl 512 为什么perl从python中捕获不同的退出代码? 解决方法
孩子可能甚至没有打电话给退出.因此,系统的返回值(又名$?)包含的信息多于退出参数.
if ( $? == -1 ) { die "Can't launch child: $!n"; } elsif ( $? & 0x7F ) { die "Child killed by signal ".( $? & 0x7F )."n"; } elsif ( $? >> 8 ) { die "Child exited with error ".( $? >> 8 )."n"; } else { print "Child executed successfullyn"; } 这是documented. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |