in reply to getting the return value from a C program

podian,
You are going to want to take a look at least two things: The first one allows you to in-line C code. The second will allow you to capture the output of an externally called C program as in:
my $foo = qx{ ./external };
Cheers - L~R

Replies are listed 'Best First'.
Re: Re: getting the return value from a C program
by graff (Chancellor) on Mar 23, 2004 at 02:50 UTC
    perldoc -f qx

    Um, the OP was asking about capturing the exit status of a C program, which involves using the "system()" call (perldoc -f system) -- not "qx" (aka the backtick operator), which just captures the program's stdout. Also -- OOPS, sorry. I should have read the docs more carefully myself, to see that qx returns stdout and sets $? -- thanks, I'm glad I finally learned that. Anyway (end of update), the more direct reference for qx is "perldoc perlop" (which is where "perldoc -f qx" tells you to look).

    Another reply below points to the usage of "system()", along with the "$?" variable -- though I prefer using a scalar that has a meaningful name, e.g.:

    my $exit_stat = system( "some_shell_command ..." ); printf "Shell_command exit status was %d\n", $exit_stat/256; print "(which means it probably failed)\n" if $exit_stat != 0;
    (closing remark to updates: my old habit of using "system()" to get the exit status, vs. using backticks to get stdout data, was simply a matter of being unaware of the $? variable, which is set in either case.)