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. Qt 五子棋

    http://blog.csdn.net/baiding1123/article/details/17194535

  2. git基础命令

     git pull 更新git status 查看文件状态git add .添加所有git commit -a -m "xxxx" 提交git push 推送至服务器git dif ...

  3. docker 使用Data Volume 共享文件

    Adding a data volume You can add a data volume to a container using the -v flag with the docker run  ...

  4. openwrt 新版IPV6问题

    我的版本是r45579,表现是路由认证后正确获取IPV6地址并且可以ping通外网,电脑可以获取地址但是连不上外网. 加一条转发规则就好了 先查看/etc/config/network里给电脑分配的地 ...

  5. session_cache_limiter 及 session 常见问题

    我点击后退按钮,为什么之前填写的东西不见 这是因为你使用了session. 解决办法: PHP代码:-------------------------------------------------- ...

  6. C语言的本质(13)——指向指针的指针

    指针可以指向基本类型,也可以指向复合类型,因此一个指针变量存放的可以是另一个指针变量的地址,则称这个指针变量为指向指针的指针变量.由于指针变量直接指向变量,所以称为"单级间址".而 ...

  7. SoftLAyer VPN

    1,安装softlayer-VPN(即跑VPN客户端)的机器与在SoftLAyer中的HardwareHostServers or VMIServer的privateIP互通

  8. Html代码seo优化最佳布局实例讲解

    搜索引擎对html代码是非常优化的,所以html的优化是做好推广的第一步.一个符合seo规则的代码大体如下界面所示. 1.<!–木庄网络博客–> 这个东西是些页面注释的,可以在这里加我的& ...

  9. HttpWebResponse请求状态代码

    HttpWebResponse请求状态代码标识 成员名称 说明 Continue 等效于 HTTP 状态 100.Continue指示客户端可能继续其请求. SwitchingProtocols 等效 ...

  10. Segment FRAM_DATA must be defined in a segment definition option (-Z, -b or -P)

    1. 网上说这个回答是 协议栈和IAR版本号不一样,这算什么神马问题 2. 网上的解决的方法是改动 options-> link -> config -> 改动里面的连接文件,可是怎 ...