system 返回值 判断

int main()
{
    pid_t status;
 
 
    status = system("./test.sh");
 
    if (-1 == status)
    {
        printf("system error!");
    }
    else
    {
        printf("exit status value = [0x%x]
", status);
 
        if (WIFEXITED(status))
        {
            if (0 == WEXITSTATUS(status))
            {
                printf("run shell script successfully.
");
            }
            else
            {
                printf("run shell script fail, script exit code: %d
", WEXITSTATUS(status));
            }
        }
        else
        {
            printf("exit status = [%d]
", WEXITSTATUS(status));
        }
    }
 
    return 0;
}
原文地址:https://www.cnblogs.com/132818Creator/p/14303580.html