File: pc.c

package info (click to toggle)
cvs 1.10.7-1.99.slink.y2k.1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 8,892 kB
  • ctags: 5,463
  • sloc: ansic: 68,307; sh: 17,664; makefile: 1,640; perl: 902; yacc: 826; csh: 181; lisp: 7
file content (62 lines) | stat: -rw-r--r-- 1,099 bytes parent folder | download | duplicates (15)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdio.h>
#include <unixio.h>
#include <stdlib.h>
#include <string.h>

int trace = 1;

extern int piped_child();
extern int piped_child_shutdown();

main (argc, argv)
  int argc;
  char ** argv;
{
  static char line[512];
  char *linep[] = {line, NULL};
  int pid;
  int tofd, fromfd;
  FILE *in, *out;
  
  while (1)
    {
    printf("\nEnter a command to run: ");
    line[0] = '\0';
    fgets(line, 511, stdin);
    if (!strlen(line))
       exit(2);

    line[strlen(line)-1] = '\0';
    pid = piped_child(linep, &tofd, &fromfd);

    in = fdopen(fromfd, "r");
    out = fdopen(tofd, "w");

#if 0
    out = fdopen(tofd, "w");
    fclose(out);
#endif

    do
       {
       if(!feof(stdin))
         {
         fprintf(stdout, "> ");
         fgets(line, 511, stdin);
         fputs(line, out);
         }
       else 
         {
         fclose(out);
         close(tofd);
         }

       fgets(line, 511, in);
       fputs(line, stdout);
       line[0] = '\0';
       } while (!feof(in));

    fprintf(stderr, "waiting for child to stop\n");
    piped_child_shutdown(pid);
    }
}