根据system函数返回值确定命令是否执行成功
2018-01-31 10:45
281 查看
#include <stdio.h> #include <stdlib.h> #include <sys/wait.h> #include <sys/types.h> int system_cmd(char *cmd) { pid_t status; status = system(cmd); if (-1 == status) { printf("create child process fail!\n"); return -1; } else { //printf("exit status value = [0x%x]\n", status); if (WIFEXITED(status)) { if (0 != WEXITSTATUS(status)) { printf("run shell script fail.\n"); return -1; } } else { printf("exit status = [%d]\n", WEXITSTATUS(status)); return -1; } } } int main() { system_cmd("twe"); return 0; }
相关文章推荐
- system执行linux命令通过返回值判断是否成功
- system函数返回(如何判断调用的shell命令是否执行成功)
- 通过system返回值判断 命令是否正确执行
- 检测进程是否存在的小函数&&检测命令是否执行成功的小函数
- linux c system函数执行命令的返回值
- C中需要检验其执行是否成功的函数(检验返回值)
- C语言典型代码---执行shell命令并判断是否成功
- shell中判断前一个命令是否执行成功
- 解决system()函数执行命令弹出dos窗口问题
- 杂学杂记(四)C/C++下使用system()函数执行命令行命令简述
- system函数在当前进程下执行一个新命令
- 如何在shell脚本中,判断一个基本命令执行是否成功?
- shell 中如何判断前一个命令是否执行成功
- C#的Unit Test如何根据exception来判断函数是否执行正确
- shell 中如何判断前一个命令是否执行成功
- 判断./configure,make等长输出命令是否执行成功
- shell 中如何判断前一个命令是否执行成功
- php执行外部命令函数:exec()、passthru()、system()、shell_exec()对比
- Python3 执行操作系统命令的函数 system 和 popen 的区别
- 在Loadrunner中如何用system函数执行系统命令