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. Servlet基础之一:Servlet基本接口与类

    1.概述 Servlet API中共有5个包,约113个接口和类: javax.servlet javax.servlet.http javax.servlet.jsp javax.servlet.a ...

  2. Fragment之一:基本原理

    1.低版本API对Fragment的支持 Fragment必须被加载进Acitivity中,才能呈现.而在低于3.0版本的API中,由于不存在Fragment,因此必须使用support包: (1)对 ...

  3. 碰到这个SB错误,'Taglist: Exuberant ctags (http://ctags.sf.net) not found in PATH. Plugin is not loaded.点办

    After launching MacVim you may get this annoying error message:'Taglist: Exuberant ctags (http://cta ...

  4. 为什么我们需要性能测试,需要loadrunner

    什么是功能: 功能按我理解就是软件实现需求,提供服务,那么功能测试就是实现的需求是否与客户给定需求一致,也就是符合预期结果 什么是性能: 功能是实现需求,提供服务,那么性能就可以理解为服务的好坏.比如 ...

  5. Leetcode算法刷题:第100题 Same Tree

    Same Tree 题目 给予两棵二叉树,判断这两棵树是否相等(即各节点的值都一样) 解题思路 分别遍历两棵二叉树,并用列表分别存储这两棵树的节点的值,比较这两个列表就可以了 class Soluti ...

  6. PHP - Mysql数据库备份类

    使用方法: require_once("backdata.class.php"); $link =@mysql_connect("localhost",&quo ...

  7. C语言当中的作用域

    在C语言当中,变量的作用域分为两种:全局变量和局部变量. 在所有函数之外声明的变量是全局变量,这些变量可以在整个程序当中被访问: 局部变量是在某一对大括号({})之间生命的变量,这些变量在这对大括号之 ...

  8. Mac 安装Qt5.1编译出现的错误解决

    错误提示: :-1: 错误:Xcode is not installed in /Volumes/Xcode/Xcode.app/Contents/Developer. Please use xcod ...

  9. 项目总结——SqlParameter的参数设置长度(size属性)

    看到很多朋友在实例化SqlParameter时,通常都没有指定参数的长度就直接给参数赋值了.就像下面的写法: new SqlParameter("@address", SqlDbT ...

  10. orapwd创建密码文件

    在CMD里输入命令如下:C:\Documents and Settings\Administrator>orapwd Usage: orapwd file=<fname> passw ...