Mail Archives: djgpp/1998/04/09/18:31:11
From: | mkeesan AT kenan DOT com (Morris M. Keesan)
|
Newsgroups: | comp.lang.c,comp.os.msdos.djgpp
|
Subject: | Re: Executing a program and obtaining its return value
|
Date: | Thu, 09 Apr 1998 21:58:24 GMT
|
Organization: | Kenan Systems Corporation
|
Lines: | 27
|
Message-ID: | <352d435b.289803812@news>
|
References: | <352C1A0D DOT 77EAB402 AT codex DOT nu>
|
NNTP-Posting-Host: | keesan.kenan.com
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
On Wed, 08 Apr 1998 20:45:01 -0400, Jeff Weeks <info AT codex DOT nu> wrote:
>Hi there,
>
>I know how I could go about running a program from inside a C program
>(using system or exec*) but neither seem to return the return value of
>the program. Is there an ANSI or POSIX way of obtaining the programs
>return value? If so, how?
ANSI C says that the return value of system() is implementation-defined,
unless the argument to system() is a null pointer (in which case a
non-zero return value means there's a command processor available).
For POSIX, use the exec family of functions, then call wait() or
waitpid() to get the exit status. Type "man 2 wait" to your Unix shell,
or try news:comp.unix.programmer for further POSIX help.
>Also, do you suppose it's portable to return pointers from executables?
>It seems to me that any system would be able to return a pointer pretty
>easily, considering pointers are almost always size_of(int) and int
>seems to be returned all the time. I'm just wondering if there are any
>odd problems I should know about.
Returning a pointer is absolutely and totally non-portable. The only
portable return values from programs are 0, EXIT_SUCCESS, and
EXIT_FAILURE.
--
Morris M. Keesan -- mkeesan AT kenan DOT com
Kenan Systems Corporation
- Raw text -