System函数
来源:互联网 发布:淘宝拒收快递运费谁出 编辑:程序博客网 时间:2024/06/05 12:08
system函数---可使用system在系统中调用系统提供的各种命令。
system的实现是通过调用fork/exec/waitpid等来实现的。
函数声明:
#include<stdlib.h>
int system(const char *cmdstring);
cmdstring---字符串指针,用于指向表示命令行的字符串。
调用fork函数失败,返回值为-1;
调用exec失败,返回值为shell操作的返回值(表示shell无法执行设定的命令);
调用waitpid失败,返回值为-1。
system函数示例(函数的不同返回情况)
#incldue<sys/types.h>
#include<stdlib.h>
#include<stdio.h>
#include<sys/wait.h>
int main(void)
{
int status;
if(status=system(NULL)<0)
{
printf("system error!\n");
exit(0);
}
printf("exit status=%d\n",status);
if((status=system("date"))<0)
{
printf("system error!\n");
exit(0);
}
if((status=system("invalidcommand"))<0)
{
printf("system error!\n");
exit(0);
}
printf("exit status=%d.\n".status);
if((status=system("eho;exit 33"))<0)
{
printf("system error!\n");
exit(0);
}
printf("exit status=%d.\n",status);
exit(0);
}
- system函数
- System函数
- system()函数
- system函数
- system ()函数
- system()函数
- system()函数
- system()函数
- system()函数
- system函数
- system()函数
- system()函数
- system() 函数
- system()函数
- system函数
- system()函数
- system函数
- System函数
- 偏好设置存储
- 常见的xml里的转义字符
- 积少成多
- document.documentElement和document.body
- 习题6-2 UVA 712 S-Trees S树
- System函数
- 公众平台测试帐号开发全流程第2篇-搭建项目
- linux下用tomcat部署产品
- Hibernate框架核心组件
- html5优越性
- DiaLogUtils报错java.lang. IllegalStateException You need to use a Theme.AppCompat theme
- 关于C艹中的笑脸问题。
- 【工作技巧】word目录
- 我的博客