Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 error codes?

like image 567
Sachin Chourasiya Avatar asked Feb 27 '23 23:02

Sachin Chourasiya


1 Answers

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.

like image 135
Eli Bendersky Avatar answered Mar 07 '23 09:03

Eli Bendersky