※ 引述《clanguage (C语言)》之铭言:
: 请问一下从 perl 呼叫其他 script 程式返回值问题
: 1.pl 呼叫 2.pl 后, 我传回值为1, 但在 1.pl 却收到 256
: 有人知道是怎么回事吗?
: 1.pl
: my $cmd = "2.pl";
: system($cmd);
: if ($? > 0) {
: B say "result=$?";
: }
: # 印出 result=256
: 2.pl
: my $ret = main();
: say "main=$ret";
: exit($ret);
: # 印出 main=1
这边 http://perldoc.perl.org/perlvar.html#Error-Variables
你也可以 man perlvar 来看
$? 的段落是这样写的:
$?
The status returned by the last pipe close, backtick (`` ) command,
successful call to wait() or waitpid(), or from the system() operator.
This is just the 16-bit status word returned by the traditional Unix wait()
system call (or else is made up to look like it). Thus, the exit value of
the subprocess is really ($?>> 8 ), and $? & 127 gives which signal, if any,
the process died from, and $? & 128 reports whether there was a core dump.
Additionally, if the h_errno variable is supported in C, its value is
returned via $? if any gethost*() function fails.
If you have installed a signal handler for SIGCHLD , the value of $?
will usually be wrong outside that handler.
Inside an END subroutine $? contains the value that is going to be
given to exit(). You can modify $? in an END subroutine to change
the exit status of your program. For example:
END {
$? = 1 if $? == 255; # die would make it 255
}
Under VMS, the pragma use vmsish 'status' makes $? reflect the actual
VMS exit status, instead of the default emulation of POSIX status;
see $? in perlvms for details.
Mnemonic: similar to sh and ksh.
你想要的资讯应该是在我标黄色的部分~