exec族函数,system函数,popen函数

一、exec族函数

execl()在调用后不会返回到原进程;
精彩博文:链接: https://blog.csdn.net/u014530704/article/details/73848573
https://blog.csdn.net/u014530704/article/details/73848573

二、system()函数

system()调用后会返回到原进程继续运行,其实system就是在调用execl函数

#include<stdlib.h>
int system(const char *command);

system()函数的返回值如下:成功,则返回进程状态值;当sh不能执行时,返回127;失败返回-1;

精彩博文:https://www.cnblogs.com/leijiangtao/p/4051387.html

三、popen

不管是execl,还是system都不能获得执行命令后的数据,都会在执行后流失在终端,那么怎样才能获得执行命令的数据呢?—popen();

#include<stdio.h>
FILE *popen(const char *command, const char *type);
int pclose(FILE *stream);

popen不会打印流里面的数据,流里面的数据还需用fread读出;

#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main(void)
{
	char ret[1024]={0};	
	FILE *fp;
	fp=popen("ps","r");
	fread(ret,1,1024,fp);
	printf("ret=%s\n",ret);
	return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值