in reply to Reading return value from C program
On most operating systems like Windows and UNIX, one program can call (execute) another. When the called program ends, it returns to the calling program a status code, which is an integer. (Normally, a code of 0 indicates success.)
If the called program is written in C, it returns this status code via the return value of the main() function. Other languages do it differently. In Perl, you can do it by giving an argument to the exit function.
When the calling program is written in Perl, and the called program is executed using the system function, the return value of that function is (or rather, contains) the status code returned by the called program. So you can do
There are other ways to execute another program (such as the qx operator), and they don't return the child's status code quite so conveniently, so in those cases you look for it in the special $? variable. E.g.:my $child_code = system( "other_program" );
my $result_text = qx( other_program ); my $child_code = $?;
|
|---|