/* program on pipe using popen fn */
# 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(argc!=2)
{
perror("\n usage :- a.out <path name>");
exit(0);
}
if((fpin=fopen(argv[1],"r"))==NULL)
{
printf("\nUnable to open %s",argv[1]);
}
if((fpout=popen(PAGER,"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);
}
# 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(argc!=2)
{
perror("\n usage :- a.out <path name>");
exit(0);
}
if((fpin=fopen(argv[1],"r"))==NULL)
{
printf("\nUnable to open %s",argv[1]);
}
if((fpout=popen(PAGER,"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