Q: Return-values of system("...") calls 
Author Message
 Q: Return-values of system("...") calls

Hello,

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.

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.

Thanks in advance.

Greetings

Andreas



Sat, 09 Nov 2002 03:00:00 GMT  
 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



Sat, 09 Nov 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. directing unix system call "system"s output

2. "system()" system call

3. Comparisons with value returned from "signal".

4. C++ "system" call

5. Running system calls "silently"

6. about "call by value" and "call by reference"

7. Q : What is returned by "return;"

8. System call "select( )" and "Message Queue"

9. Raising "Invalid Property Values"

10. "Faking" null in value types

11. Send integer value by "send( )"

12. What is the return value of "system()"?

 

 
Powered by phpBB® Forum Software