Wednesday, June 20, 2012

/* program on pipe using popen function */
# include <sys/wait.h>
# include <stdio.h>
# include <stdlib.h>
# define MAXLINE 4096

# define PAGER "${PAGER:-more}"

int main(int argc,char*argv[])
{
    char line[MAXLINE];
    FILE *fpin,*fpout;

/*
    if((fpin=fopen(argv[1],"r"))==NULL)
    {
    printf("\nUnable to open %s",argv[1]);
    }
*/

    if((fpout=popen("ls *.c","w"))==NULL)
    perror("popen error...");
   
    while(fgets(line,MAXLINE,fpin))
    {
        if(fputs(line,fpout)==EOF)
        perror("\n fput error...");
    }
   
    if(ferror(fpin))
    perror("fgets error...");
    if(pclose(fpout)==-1)
    perror("pclose error..");
exit(0);
}

   
   

   
   

No comments:

Post a Comment