Here is the input file for page.c
[cdalten@localhost oakland]$ more tri.c
Code:
#include <stdio.h>
int main(void)
{
printf("What's going on here??!\n");
return 0;
}
and here is page.c itself.
[cdalten@localhost oakland]$ more page.c
Code:
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#define PAGER "${PAGER:~more}"
int main(int argc, char *argv[])
{
char line[BUFSIZ];
FILE *fpin, *fpout;
if(argc !=2) {
fprintf(stderr, "not enough args\n");
exit(1);
}
if((fpin = fopen(argv[1], "r")) == NULL) {
fprintf(stderr, "fopen error\n");
exit(1);
}
if ((fpout = popen("/bin/more", "w")) == NULL) {
fprintf(stderr, "popen error\n");
exit(1);
}
while (fgets(line, BUFSIZ, fpin) != NULL) {
if (fputs(line, fpout) == EOF) {
fprintf(stderr, "fputs error to pipe\n");
exit(1);
}
}
if(pclose(fpout) == -1) {
fprintf(stderr, "pclose error\n");
exit(1);
}
exit(0);
}
When I run it, I get...
[cdalten@localhost oakland]$ gcc -Wall page.c -o page
[cdalten@localhost oakland]$ ./page tri.c
#include <stdio.h>
int main(void)
{
printf("What's going on here??!\n");
return 0;
}
[cdalten@localhost oakland]$
The question is, does fputs() in page.c print the standard output in the parent or the child process?