forked from wenjun1055/c
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15.7.c
More file actions
39 lines (31 loc) · 689 Bytes
/
15.7.c
File metadata and controls
39 lines (31 loc) · 689 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#define MAXLINE 1024
int main(void)
{
char line[MAXLINE];
FILE *fpin;
if ((fpin = popen("./15.6", "r")) == NULL) {
printf("popen error\n");
exit(-1);
}
for ( ; ; ) {
fputs("prompt> ", stdout);
fflush(stdout);
if (fgets(line, MAXLINE, fpin) == NULL) {
break;
}
if (fputs(line, stdout) == EOF) {
printf("fputs error to pipe");
exit(-1);
}
}
if (pclose(fpin) == -1) {
printf("pclose error\n");
exit(-1);
}
putchar("\n");
return 0;
}