开发者

What's the difference between system() in C and Perl?

The system() function will launch a new process from C and a Perl script.

What exactly are the differences between processes called by system() in C and from Perl scripts, in terms of representation of 开发者_StackOverflow中文版error codes?


A little research brings up:

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). See also "exec". This is not what you want to use to capture the output from a command, for that you should use merely backticks or qx//, as described in "STRING" in perlop. Return value of -1 indicates a failure to start the program or an error of the wait(2) system call (inspect $! for the reason).

And the docs of wait say:

Behaves like the wait(2) system call on your system: it waits for a child process to terminate and returns the pid of the deceased process, or -1 if there are no child processes. The status is returned in $? and ${^CHILD_ERROR_NATIVE} . Note that a return value of -1 could mean that child processes are being automatically reaped, as described in perlipc.


Sources: This was taken from perldoc. Here's a tutorial on system in Perl.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜