- close(pipefd[1]);
- /* parent continue on */
- tap = fdopen(pipefd[0], "r");
+ if (cpid == 0) {
+ /* child */
+ close(pipefd[0]); /* close read end */
+ close(1); /* close stdout */
+ dup(pipefd[1]); /* set stdout to the write end of the pipe */
+ execlp(run->name, run->name, NULL);
+ /* only gets here if exec failed */
+ printf("Bail Out! exec %s failed: %s\n", run->name, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ close(pipefd[1]);
+ /* parent continue on */
+ tap = fdopen(pipefd[0], "r");
+ } else {
+ tap = stdin;
+ }