判断system()执行shell脚本是否正常执行结束

来源:互联网 发布:明礼仪知荣辱演讲稿 编辑:程序博客网 时间:2021/03/04 18:15
    #include <stdio.h>       #include <stdlib.h>       #include <sys/wait.h>       #include <sys/types.h>             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;      }  

0 0
原创粉丝点击