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: ...
随机推荐
- 动态链接库的生成(dll)和 动态链接库隐式and显式调用
一.构建动态链接库(dll.dll dll.lib dll.h) 说明: .dll 是在执行程序是调用 .lib 是在连接程序是调用 .h是在编译程序时调用 1.头文件(声明导入函数):_decl ...
- 【iOS】objective-c 文档生成工具 appledoc
最近做ios framework的一些测试,提供给其他开发者使用的framework,API文档变得更加重要,以前没有接触过,这次尝试使用了一把appledoc来生成一下文档,感觉还不错. 首先,是从 ...
- Mysql JOIN优化。
join性能自行百度,google 数据60w+,这里我只测试了一个limit , ) ,) AS C LEFT JOIN table2 AS B ON C.e_id=B.id; ) ,;
- html5属性placeholder的js 向下兼容支持(jquery版)
placeholder是html5表单特性中比较好用的一条,但是苦于其向下兼容性,所以一般要做向下兼容的站点都不敢用,如果有用到的地方,也是用js简单模拟而实现的,那么有没有一个一劳永逸的方法去解决这 ...
- windows 激活远程桌面服务
- static_cast与dynamic_cast转换 最简单的理解
3.1 static_cast用法:static_cast < type-id > ( exdivssion ) 该运算符把exdivssion转换为type-id类型,但没有运行时类型检 ...
- 一道C语言面试题:写一个宏,将16位的整数转为Big Endian
题目:输入16位整数x,如0x1234,将其转为Big Endian格式再输出,此例为输出 0x3412 来源:某500强企业面试题目 思路:将x左移8位得到a,将x右移8位得到b,a+b即为所得 / ...
- Android 自定义PopupWindow动画效果
public class RollActivity extends Activity { private View view; private Button btn; private PopupWin ...
- ASP.NETURL地址防注入过滤问题
首先在Global.asax.cs里面配置一个 提交事件 不用过滤所有的地址 过滤 GET POST的地址就行了 /// <summary> /// 防止sql注入 /// </s ...
- wxpython 拖放
拖放对用户是非常直观.它在许多桌面应用程序,用户可以复制或只需用鼠标拖动和删除另一个窗口中移动对象从一个窗口到另一个中. 拖放操作包括以下步骤 - 声明拖放目标 创建数据对象 创建 wx.DropSo ...