Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1752247
  • 博文数量: 335
  • 博客积分: 4690
  • 博客等级: 上校
  • 技术积分: 4341
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-08 21:38
个人简介

无聊之人--除了技术,还是技术,你懂得

文章分类

全部博文(335)

文章存档

2016年(29)

2015年(18)

2014年(7)

2013年(86)

2012年(90)

2011年(105)

分类: C/C++

2012-03-13 22:48:07

  1. #include "apue.h"
  2. #include <sys/wait.h>

  3. #define PAGER "${PAGER:-more}" /* environment or default */

  4. int main(int argc,char * argv[])
  5. {
  6.     char line[MAXLINE];
  7.     FILE * fpin, * fpout;

  8.     if (argc != 2)
  9.         err_quit(" uasge: a.out );
  10.     if ((fpin = fopen(argv[1],"r")) == NULL )
  11.         err_sys("can't open file ");
  12.     if ((fpout = popen(PAGER,"w")) == NULL )
  13.         err_sys("popen error");
  14.     /*

  15.      * copy argv[1] to pager */
  16.     while( fgets(line,MAXLINE,fpin) != NULL )
  17.         if (fputs(line,fpout) == EOF )
  18.             err_sys("fputs error");
  19.     if (ferror(fpin))
  20.         err_sys("fputs error");
  21.     if (pclose(fpout) == -1 )
  22.         err_sys("fput error");
  23.     exit(0);
  24. }
ubuntu@ubuntu-virtual-machine:~/Desktop/apue$ gcc -Wall -o c15-3 c15-3.c error.c 
./c15-3  error.c
#include "apue.h"
#include /* for definition of errno */
#include /* iso c variable arguement */ 
 
static void err_doit(int ,int,co..................
注意 函数的使用方式
popen(cmdstring,"mode");
打开管道,执行命令,根据mode的方式,
并以文件指针的方式返回:
FILE * fp
r:  说明管道以可读的方式返回文件指针
w: 说明管道已可写的方式返回文件指针













阅读(922) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~