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()函数详解的更多相关文章

  1. Linux C popen()函数详解

    表头文件 #include<stdio.h> 定义函数 FILE * popen( const char * command,const char * type); 函数说明 popen( ...

  2. linux的system () 函数详解

    linux的system () 函数详解     system(执行shell 命令)相关函数        fork,execve,waitpid,popen表头文件        #i nclud ...

  3. python中的subprocess.Popen()使用详解---以及注意的问题(死锁)

    从python2.4版本开始,可以用subprocess这个模块来产生子进程,并连接到子进程的标准输入/输出/错误中去,还可以得到子进程的返回值. subprocess意在替代其他几个老的模块或者函数 ...

  4. malloc 与 free函数详解<转载>

    malloc和free函数详解   本文介绍malloc和free函数的内容. 在C中,对内存的管理是相当重要.下面开始介绍这两个函数: 一.malloc()和free()的基本概念以及基本用法: 1 ...

  5. NSSearchPathForDirectoriesInDomains函数详解

    NSSearchPathForDirectoriesInDomains函数详解     #import "NSString+FilePath.h" @implementation ...

  6. JavaScript正则表达式详解(二)JavaScript中正则表达式函数详解

    二.JavaScript中正则表达式函数详解(exec, test, match, replace, search, split) 1.使用正则表达式的方法去匹配查找字符串 1.1. exec方法详解 ...

  7. kzalloc 函数详解(转载)

    用kzalloc申请内存的时候, 效果等同于先是用 kmalloc() 申请空间 , 然后用 memset() 来初始化 ,所有申请的元素都被初始化为 0. view plain /** * kzal ...

  8. Netsuite Formula > Oracle函数列表速查(PL/SQL单行函数和组函数详解).txt

    PL/SQL单行函数和组函数详解 函数是一种有零个或多个参数并且有一个返回值的程序.在SQL中Oracle内建了一系列函数,这些函数都可被称为SQL或PL/SQL语句,函数主要分为两大类: 单行函数 ...

  9. jQuery.attr() 函数详解

    一,jQuery.attr()  函数详解: http://www.365mini.com/page/jquery-attr.htm 二,jQuery函数attr()和prop()的区别: http: ...

随机推荐

  1. Java之定时任务详解

    在我们编程过程中如果需要执行一些简单的定时任务,无须做复杂的控制,我们可以考虑使用JDK中的Timer定时任务来实现.下面就其原理.实例以及Timer缺陷三个方面来解析java Timer定时器. 在 ...

  2. html5属性placeholder的js 向下兼容支持(jquery版)

    placeholder是html5表单特性中比较好用的一条,但是苦于其向下兼容性,所以一般要做向下兼容的站点都不敢用,如果有用到的地方,也是用js简单模拟而实现的,那么有没有一个一劳永逸的方法去解决这 ...

  3. Esper

    https://www.igvita.com/2011/05/27/streamsql-event-processing-with-esper/ http://torycatkin.iteye.com ...

  4. Windows消息拦截技术的应用(作者博客里有许多相关文章)

    民航合肥空管中心 周毅 一.前 言 众所周知,Windows程式的运行是依靠发生的事件来驱动.换句话说,程式不断等待一个消息的发生,然后对这个消息的类型进行判断,再做适当的处理.处理完此次消息后又回到 ...

  5. Dispatcher.BeginInvoke()方法使用不当导致UI界面卡死的原因分析

    原文:Dispatcher.BeginInvoke()方法使用不当导致UI界面卡死的原因分析 前段时间,公司同事开发了一个小工具,在工具执行过程中,UI界面一直处于卡死状态. 通过阅读代码发现,主要是 ...

  6. C语言的本质(14)——不完全类型和复杂声明

    ISO 将 C 的类型分为三个不同的集合: 函数.对象和不完全类型三大类.函数类型很明显:对象类型包含其他一切,除非不知道对象的大小.该标准使用术语"对象类型"指定指派的对象必须具 ...

  7. android开发的问题集(二)

    (1)子线程对UI线程操作的简便方法 子线程方法用 Looper.prepare(); 结束时候用 Looper.loop();  

  8. Nutch环境搭建

    1. 环境准备 HOST:Ubuntu12.04LTS JDK: jdk-7u45-linux-i586.rpm Nutch:apache-nutch-1.7-bin.tar.gz Solr:solr ...

  9. Oracle password expire notices

    /usr/local/webserver/tomcat6/logs/logbak/zsxxw.log.2015-03-21.txt:2015-03-22 00:47:26,366 ORA-28002: ...

  10. 定义file input

    <div class="inputFileWrapper"> <label for="inputFile"> <input typ ...