system 返回值 判断

int main()
{
    pid_t status;
 
 
    status = system("./test.sh");
 
    if (-1 == status)
    {
        printf("system error!");
    }
    else
    {
        printf("exit status value = [0x%x]\n", status);
 
        if (WIFEXITED(status))
        {
            if (0 == WEXITSTATUS(status))
            {
                printf("run shell script successfully.\n");
            }
            else
            {
                printf("run shell script fail, script exit code: %d\n", WEXITSTATUS(status));
            }
        }
        else
        {
            printf("exit status = [%d]\n", WEXITSTATUS(status));
        }
    }
 
    return 0;
}

 

posted @ 2021-01-20 16:26  HappyCoder_1  阅读(144)  评论(0编辑  收藏  举报