popen()函数详解
popen()函数
/*============================================
> Copyright (C) 2014 All rights reserved.
> FileName:popen.c
> author:donald
> date:2014/08/22/ 12:20:53
> details:
==============================================*/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 512
int main(int argc, const char *argv[])
{
FILE *fp;
char cmd[N],buf[N];
memset(cmd,,N);
memset(buf,,N);
#if 0
fgets(cmd,N,stdin);
fp = popen(cmd,"r");
while(fgets(buf,N,fp) != NULL)
printf("%s",buf);
#endif
#if 1
fgets(cmd,N,stdin);
fp = popen(cmd,"w");
//这里把用户输入写进了cmd,
if(fp == NULL)
printf("error\n");
fgets(buf,N,fp);
printf("123%s\n",buf);//测试时使用
#endif
pclose(fp);
return ;
}
open_mode为“r”
open_mode为“w”
/*============================================
> Copyright (C) 2014 All rights reserved.
> FileName:my_ponen.c
> author:donald
> details:
==============================================*/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, const char *argv[])
{
int left,right,sum;
FILE* fp ;
char cmd[] = "";
while(){
scanf("%d%d",&left,&right);
sprintf(cmd,"%s %d %d",argv[],left,right);
fp = popen(cmd,"r");
fscanf(fp,"%d",&sum);
printf("result is : %d\n",sum); pclose(fp);
}
return ;
}
目标函数
/*============================================
> Copyright (C) 2014 All rights reserved.
> FileName:mystring.c
> author:donald
> details:
==============================================*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 1024
int main(int argc, const char *argv[])
{
int index;
char buf[N];
memset(buf,,N);
for(index = argc - ;index > ;index --){
strcat(buf,argv[index]);
strcat(buf," ");
}
printf("%s\n",buf);
return ;
}
popen()函数详解的更多相关文章
- Linux C popen()函数详解
表头文件 #include<stdio.h> 定义函数 FILE * popen( const char * command,const char * type); 函数说明 popen( ...
- linux的system () 函数详解
linux的system () 函数详解 system(执行shell 命令)相关函数 fork,execve,waitpid,popen表头文件 #i nclud ...
- python中的subprocess.Popen()使用详解---以及注意的问题(死锁)
从python2.4版本开始,可以用subprocess这个模块来产生子进程,并连接到子进程的标准输入/输出/错误中去,还可以得到子进程的返回值. subprocess意在替代其他几个老的模块或者函数 ...
- malloc 与 free函数详解<转载>
malloc和free函数详解 本文介绍malloc和free函数的内容. 在C中,对内存的管理是相当重要.下面开始介绍这两个函数: 一.malloc()和free()的基本概念以及基本用法: 1 ...
- NSSearchPathForDirectoriesInDomains函数详解
NSSearchPathForDirectoriesInDomains函数详解 #import "NSString+FilePath.h" @implementation ...
- JavaScript正则表达式详解(二)JavaScript中正则表达式函数详解
二.JavaScript中正则表达式函数详解(exec, test, match, replace, search, split) 1.使用正则表达式的方法去匹配查找字符串 1.1. exec方法详解 ...
- kzalloc 函数详解(转载)
用kzalloc申请内存的时候, 效果等同于先是用 kmalloc() 申请空间 , 然后用 memset() 来初始化 ,所有申请的元素都被初始化为 0. view plain /** * kzal ...
- Netsuite Formula > Oracle函数列表速查(PL/SQL单行函数和组函数详解).txt
PL/SQL单行函数和组函数详解 函数是一种有零个或多个参数并且有一个返回值的程序.在SQL中Oracle内建了一系列函数,这些函数都可被称为SQL或PL/SQL语句,函数主要分为两大类: 单行函数 ...
- jQuery.attr() 函数详解
一,jQuery.attr() 函数详解: http://www.365mini.com/page/jquery-attr.htm 二,jQuery函数attr()和prop()的区别: http: ...
随机推荐
- V - stl 的 优先队列 Ⅱ
Description Because of the wrong status of the bicycle, Sempr begin to walk east to west every morni ...
- asp.net后台向前端输出js脚本的三种方法
//这个方法最快,因为它会输出到html标签之前 Response.Write("<script type='text/javascript'>alert('这个最快')< ...
- mac/linux install hg
MAC OSX 10.9: sudo port -v install mercurial or easy_install mercurial
- API例子:用Python驱动Firefox采集网页数据
1,引言 本文讲解怎样用Python驱动Firefox浏览器写一个简易的网页数据采集器.开源Python即时网络爬虫项目将与Scrapy(基于twisted的异步网络框架)集成,所以本例将使用Scra ...
- jQuery插件jqplot的详细配置说明和渲染器
jQuery插件jqplot的详细配置说明和渲染器 (2012-08-23 08:57:42) 转载▼ 标签: jqplot 详细配置 渲染器 it 分类: 技术类 jQuery.jqplot插件的官 ...
- Seafile 推出 “分布式文件同步技术” 打造的私有云服务
近两年来 Dropbox 等云储存服务迅速窜红,各大巨头纷纷推出自家的云储存服务(苹果的 iCloud, 微软的 SkyDrive, Google 即将推出的 GDrive),国内也有类似的服务(金山 ...
- Android实现ListView或GridView首行/尾行距离屏幕边缘距离
直接上关键属性: 设置ListView或GridView的android:clipToPadding = true, 然后通过paddingTop和paddingBottom设置距离就好了.
- gem update --system 302 错误 解决方案(转)
具体过程如下: 1.InstantRails-2.0安装后,在配置环境变量path中配置ruby/bin目录(如果系统中有多个RUBY,执行命令行的时候系统认的就是path中的) 2.进入DOS命令行 ...
- 【hihocoder1255 Mysterious Antiques in Sackler Museum】构造 枚举
2015北京区域赛现场赛第2题. 题面:http://media.hihocoder.com/contests/icpcbeijing2015/problems.pdf OJ链接:http://hih ...
- eclipse ctrl链接设置
选择[Window]菜单 Preferences ——>General——>Editors——>Text Editors——>Hyperlinking