
Q: Return-values of system("...") calls
Quote:
> I am wondering whether anybody could share his experience with me on the
> portability calls such as
> system("...");
> with regard to their return values. What I want to do is to call a C
> program of mine from within another C program using a system call, and
> the called program should return a status variable, which I am going to
> use in the calling program to determine an action. I read in the C FAQ
> by Steve Summit that these values need not be portable. In a book on
> Linux programming (whose name escaped me, but I can find out), I found a
> list of possible values, and in which range the returned value is truly
> the value returned by the called program and not the system.
Which list is, of course, valid on Linux only, and perhaps even only
using the same compiler that the writer of the book used.
Quote:
> Can anybody share with me their experience on this or related matters? I
> realise that this is not strictly speaking a C-programming question, but
> I thought that some of the posters may be able to help me out in this
> matter.
Strictly speaking, you can _return_ 0, EXIT_SUCCESS, and EXIT_FAILURE
from your program if you want complete portability. I sometimes (when I
need it) ignore this and use any value between 0 and 255, because I
happen to know that that is what my system supports.
However, none of this is useful for system(), because its return value
is implementation defined. In my case, because MS-DOS is so primitive
steam power would be an improvement, this means that command.com returns
{*filter*} all and system() always returns 0, so I don't get the return
value from the called program. Which is a pain. If your system does
return this value, you can use it, but such values will always be
system-dependent.
Richard