开发者

Why system doesn't return main's value?

开发者 https://www.devze.com 2023-03-21 08:12 出处:网络
[root@ test]$ cat return1开发者_如何转开发0.c #include <stdio.h> int main(int argc, char *argv[]){
[root@ test]$ cat return1开发者_如何转开发0.c
#include <stdio.h>
int main(int argc, char *argv[]){
    return 10;
}
[root@ test]$ perl -e 'print system("/path_to_return10")'
2560

I was expecting 10 but got 2560,why?


See $? in perldoc perlvar.

You got 10 * 256 (return value = 10) + 0 * 128 (there was no core dump) + 0 (process wasn't killed by signal).


as specified in the documentation for the system call in perl (http://perldoc.perl.org/functions/system.html):

The return value is the exit status of the program as returned by the wait call. To get the actual exit value, shift right by eight (see below).

indeed: 2560 >> 8 = 10

0

精彩评论

暂无评论...
验证码 换一张
取 消