Re: return code wierdness
Posted in 1994
Chuck Jones (cej@ccsitn.att.com) writes: > int fix_exit_val(passed) > int passed; > { > return((passed & 0x0000ff00) >> 8); > } Here is a function which runs a command and returns a cleaned up version of its status which I use in our SunOS4.x/Solaris 2.x environment #include <sys/wait.h> int do_cmd(char *cmd, char **cmdV) /* execute and time the cmd */ { pid_t status; pid_t pid; int rc; if ( (pid = fork()) < 0 ) SysError("fork error"); else if ( pid == 0 ) { /* in the child here */ if ( execvp(cmd, cmdV) < 0 ) SysError("exec error"); } if ( waitpid(pid, &status, 0) < 0 ) SysError("wait error"); /* pull out return code from program run by system */ if ( WIFEXITED(status) ) rc = WEXITSTATUS(status); else if ( WIFSIGNALED(status) ) rc = WTERMSIG(status); else rc = (status & 0xff00) >> 8; /* I don't know, just shove the byte in */ return rc; }