[NTLUG:Discuss] OT C system call question
steve
sjbaker1 at airmail.net
Mon Jan 30 20:22:29 CST 2006
Fred James wrote:
> All
> In C there is "system"
> (SYNOPSIS
> #include <stdlib.h>
>
> int system (const char *string);
> )
>
> What I think I have found is that if the command inside the ( ... ) is a
> shell script and it returns a numeric value (as in: exit $i), the C
> program will see it as that number multiplied by 256 (i.e., 0 is 0, 1
> becomes 256, 2 becomes 512, etc.). [these test were run on an SGI IRIX
> 6.4 machine]
'man system' says:
RETURN VALUE
The value returned is -1 on error (e.g. fork failed), and
the return status of the command otherwise. This latter
return status is in the format specified in wait(2).
...and 'wait(2)' says that there are macro's provided to extract the
exit code from the returned result. So if you want to do this portably,
you should probably use the macro's described in 'man 2 wait'.
> Can anyone confirm or deny that,
Yep - I can confirm that.
> or offer any enlightenment, please?
Enlightenment costs extra.
More information about the Discuss
mailing list