Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!samsung!zaphod.mps.ohio-state.edu!wuarchive!udel!haven!adm!xadmx!jp27+@andrew.cmu.edu From: jp27+@andrew.cmu.edu (Jacques Parker) Newsgroups: comp.unix.wizards Subject: Pipes & Forks Message-ID: <21729@adm.BRL.MIL> Date: 12 Dec 89 19:08:51 GMT Sender: news@adm.BRL.MIL Lines: 59 I made the following program. When compiled & run, it will accept input, but not act on it. It should accept commands, and the child process should receive and execute them. This does not happen until the program is terminated (Enter ^D). Any ideas? How do I insure that the child receives the parents output immediately? Thank you for any help. Jacques Parker #include #define MAXLEN 100 #define ST_INP 0 #define ST_OUT 1 extern char **environ; char **arg = { "/bin/csh","-x"}; main(argc,argv,envp) int argc; char **argv, **envp; { int pd[2]; int pid; int bak_inp = dup (ST_INP);/* Backup the input FD */ int bak_out = dup (ST_OUT);/* Backup the output FD */ if (pipe(pd) < 0) printf("%s: Can't create pipe", cmd); dup2(pd[1], ST_OUT); /* ST_OUT --> pipe WRITE */ dup2(pd[0], ST_INP); /* ST_INP --> pipe READ */ if ((pid = fork()) < 0) printf("%s: Can't spawn a process.", cmd); if (pid == 0) { dup2(bak_out, ST_OUT); /* child out --> ST_OUT */ /* child in --> Pipe READ */ execvp(arg[0],arg,environ); printf("Shell not started. '%s' failed.",cmd); } dup2(bak_inp,ST_INP); /* parent out --> Pipe WRITE */ /* parent in --> ST_INP */ while (gets(cmd) != NULL) { /* Enter ^D to end. */ printf("%s\n,cmd); fflush(NULL); } } Address: internet jp27+@andrew.cmu.edu, uucp ...!{harvard,uunet}!andrew.cmu.edu!jp27, bitnet jp27%andrew@cmccvb.bitnet.