repo.or.cz
/
lcapit-junk-code.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
Introduce old redir program
[lcapit-junk-code.git]
/
books
/
apue
/
popen.c
blob
ef4dadb1025894d3c351baa38c2dae0ea51ab47a
1
#include <stdio.h>
2
#include <string.h>
3
#include <stdlib.h>
4
5
int
main
(
int
argc
,
char
*
argv
[])
6
{
7
FILE
*
file
;
8
char
buf
[
1024
];
9
10
file
=
popen
(
"ls *.c"
,
"r"
);
11
if
(!
file
) {
12
perror
(
"open()"
);
13
exit
(
1
);
14
}
15
16
memset
(
buf
,
'\0'
,
sizeof
(
buf
));
17
while
(
fgets
(
buf
,
sizeof
(
buf
),
file
) !=
NULL
) {
18
printf
(
"%s"
,
buf
);
19
memset
(
buf
,
'\0'
,
sizeof
(
buf
));
20
}
21
22
pclose
(
file
);
23
return
0
;
24
}