Introduce old redir program
[lcapit-junk-code.git] / books / apue / popen.c
blobef4dadb1025894d3c351baa38c2dae0ea51ab47a
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
5 int main(int argc, char *argv[])
7 FILE *file;
8 char buf[1024];
10 file = popen("ls *.c", "r");
11 if (!file) {
12 perror("open()");
13 exit(1);
16 memset(buf, '\0', sizeof(buf));
17 while (fgets(buf, sizeof(buf), file) != NULL) {
18 printf("%s", buf);
19 memset(buf, '\0', sizeof(buf));
22 pclose(file);
23 return 0;