On Unix, if you call system() on a command that returns an exit code of 1, the return code of the system command will be 256.
You need to shift the return code right 8 bits to get the exit code of the program you ran. The format of the exit code corresponds to that used by waitpid, and is defined in <sys/wait.h>.
The macro WEXITSTATUS is used to pull out the child process status.
On Unix, WEXITSTATUS is defined in <sys/wait.h> as follows:
#define WEXITSTATUS(stat) ((int)(((stat)>>8)&0xFF))
On Windows, WEXITSTATUS is defined in win32.h as follows:
#define WEXITSTATUS(w) (w)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment