Alan Balmer <al******@att.net> writes:
On Mon, 07 Jul 2003 18:24:13 -0400, Eric Sosman <Er*********@sun.com>
wrote:
[...] The value returned by system() is implementation-defined,
and may or may not have anything to do with the exit status
of the invoked program.
Implementation defined, yes, but defined by the same implementation on
which the program is being executed,
Agreed.
thus likely to be consistent with
any shell implemented on the same system.
Not necessarily. In particular,
<OT>
you might want to try the following on your Solaris system:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int result = system("/bin/false");
printf("result = %d\n", result);
return result;
}
"/bin/false" does an "exit 255". The value returned by system() is
65280, or 255 << 8. When you return this value from the main program,
all but the low-order 8 bits are stripped off, leaving 0.
</OT>
The details are, of course, implementation-defined; the point is that
they can be implementation-defined in surprising ways, even on systems
you're familiar with.
--
Keith Thompson (The_Other_Keith)
ks*@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"