system函数的返回值和执行脚本的返回值
The value returned is -1 on error (e.g. fork() failed), and the return
status of the command otherwise. This latter return status is in the
format specified in wait(2). Thus, the exit code of the command will
be WEXITSTATUS(status). In case /bin/sh could not be executed, the
exit status will be that of a command that does exit(127).
- #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;
- }
was returned for a child process that
terminated normally.
WEXITSTATUS(stat_val) If the value of WIFEXITED(stat_val) is
non-zero, this macro evaluates to the
low-order 8 bits of the status argument
that the child process passed to _exit()
or exit(), or the value the child
process returned from main().
- #include <stdio.h>
- #include <stdlib.h>
- #include <signal.h>
- int main(int argc ,char *argv[])
- {
- signal(SIGCHLD,SIG_IGN);
- int status = system("ls -l");
- if(status == -1)
- {
- printf("system fork faild !\n");
- }
- 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;
- }
system函数的返回值和执行脚本的返回值相关推荐
- redis有值查询返回null_redis运行lua脚本hmget返回值为空判断问题-Go语言中文社区...
1.redis中准备测试数据 hmset test abcd 123 ABCD 456 hgetall test 2.网上有人说用内置函数next()判断 redis-cli -c -p 8000 - ...
- python接口返回状态码,Python脚本接口返回正常,状态码405
最近些Python接口脚本时调用post接口时返回结果正常,状态码却不对. ,代码如下: 此接口完成的功能为新增一个角色,角色添加成功返回角色的id信息,但是状态码为405,405是Method No ...
- linux下system函数详解
一.system函数的简单介绍 头文件 #include <stdlib.h>函数定义int system(const char * string); 函数说明 system()会调用fo ...
- linux下system函数的深入理解
这几天调程序(嵌入式linux),发现程序有时就莫名其妙的死掉,每次都定位在程序中不同的system()函数,直接在shell下输入system()函数中调用的命令也都一切正常.就没理这个bug,以为 ...
- system函数的总结
最近在看APUE第10章中关于system函数的POSIX.1的实现.关于POSIX.1要求system函数忽略SIGINT和SIGQUIT,并且阻塞信号SIGCHLD的论述,理解得不是很透彻,本文就 ...
- system函数深度理解
转载地址:https://www.cnblogs.com/tdyizhen1314/p/4902560.html 注:从其它地方转的非常好的一篇文章,值得深究! 这几天调程序(嵌入式linux),发现 ...
- C++之system函数
转载自:http://www.xuebuyuan.com/2119209.html 1.windows操作系统下system () 函数详解(主要是在C语言中的应用) 函数名: system 功 能: ...
- shell中执行脚本并显示到终端和保存到日志文件中
我们知道,在shell中执行脚本会返回一定信息到终端屏幕上 ,但是有一些特殊情况,如以下情况: 1)显示到终端中 echo "abck" 以上在手动执行脚本中是可以的,如果是编写 ...
- abaqus的python安装文件在哪_python、abaqus执行脚本路径
python中获取执行脚本路径方法 1.sys.path[0]:获取执行脚本目录绝对路径 #每次执行脚本时,python会将执行脚本目录加入PYTHONPATH环境变量中(sys.path获取) #! ...
最新文章
- SQL语句关键字执行顺序
- CMMI5级组织如何设定年度目标
- Union-Find 算法应用
- undertow服务器分析_进入Undertow Web服务器
- jQuery选择id属性带有.点符号元素的方法
- [转载]Hamachi 安装过程
- 试戴系统完全开放—zoomla!逐浪cms在后4.6时代的又一个亮点
- 通过char与varchar的区别,学习可变长的字符类型
- Windows2003远程桌面无用户限制
- java计算经纬度距离_LeetCode 题解 |461. 汉明距离
- 什么是 npm ?npm 下载安装使用
- C语言测量平差课程设计,测量平差课程设计-20210419024415.docx-原创力文档
- CS5211替代LT7211B参数特性与优势|DP转LVDS方案
- clickhouse - 第三章:内置对象 之 第二节:table表操作 - 创建表与删除表
- 考研英语(二)——简单句
- 如何有效地阅读技术书籍
- Cocos2dx版本介绍【至3.10版】
- 每日词根——sol(完整可靠安慰,太阳严肃)
- 产品三维模型在线展示
- 9个适合上班族晚上在家就能赚钱的副业推荐(建议收藏)
热门文章
- asterisk1.8 账号信息mysql存储(动态)
- java java.lang_Java之java.lang.IllegalMonitorStateException
- 【转】Win10系统怎么设置无线做AP热点_win10设置无线为ap热点的步骤
- 【转】如何在 Visual Studio 2019 中连接中国版 Azure
- turtlebot3入门教程
- Asp.Net WebForm生命周期的详解
- 【Python CheckiO 题解】Remove Accents
- PWN-COMPETITION-HGAME2022-Week1
- 【Python学习】 - anaconda中spyder的常用快捷键总结
- 【POJ - 2632】Crashing Robots(模拟)