....
#include <sys/wait.h>
....
int rc, status;
status = system ( "your_command_here" );
rc = WEXITSTATUS ( status ); // rc contains the exit status
....
When you say you want the exit status of a process you initiate with execlp (
), I assume that you perform a species of wait ( ) on it.
....
int rc, status;
....
wait ( &status );
rc = WEXITSTATUS ( status ); // rc contains the exit status
....
system ( ) returns the ``process'' status of the child process that it
launches. wait ( &status ) places the ``process'' status of the process being
waited on in ``status''. The process status is an integer that contains the
following tidbits of information ORed together:
a) Did the process perform an exit ( ) or was it terminated by a signal
b) If terminated by a signal, the terminating signal number
c) If it performed an exit ( ), the exit status (i.e. argument to exit ( )).
d) Whether the process dumped core (this is not stipulated by POSIX
guidelines, however)
In order to access these bits of information separately, you have to use the
macros defined in <sys/wait.h>. The macro to extract the exit status from the
process status is WEXITSTATUS ( ).
> hi,
> would like to know what should i do if i want to know the exit
> status of a command that was executed by a C++ application using
> system or fork/execlp ! the system and execlp returns the error
> code while executing the command but not the exit/status code returned/set
> by the command itself.
> thanks in advance
> chirag