标签:logs clu img blog pcl src 执行 open set
-----------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
int main(void)
{
FILE *fp;
//命令执行的结果放置在fp指向的结构体缓冲中
fp = popen("cat /etc/passwd","r");
char buf[512];
memset(buff,0,sizeof(buf));
while(fgets(buf,sizeof(buf),fp) != NULL)
{
printf("%s",buf);
}
pclose(fp);
printf("------------------------------\n");
//为wc命令提供统计的数据
fp = popen("wc -l","w");
//向fp指向的结构体缓存中写入数据
fprintf(fp,"1\n2\n3\n");
pclose(fp);
exit(0);
}
标签:logs clu img blog pcl src 执行 open set
原文地址:http://www.cnblogs.com/lvdh1314/p/6511516.html