#include #include #include #include #include int main() { const char *cmd = "./my_prog.pl"; const int RESPONSE_FD = 63; int pfd[2], status; char buffer[100]; int rv; status = pipe(pfd); if(status == -1) { printf("Could not open pipe\n"); exit(1); } else { printf("The filedescriptors are: %d %d\n", pfd[0], pfd[1]); } status = fork(); if(status == 0) { printf("This is the child\n"); /* dup output/writing side of pipe */ status = dup2(pfd[1], RESPONSE_FD); /* close unused input side */ close(pfd[0]); if(status == -1) { printf("dup2 failed\n"); exit(1); } execl(cmd, cmd, (char *)0); } else { printf("This is the parent\n"); /* close unused output side of pipe */ close(pfd[1]); /* read from input side */ while(read(pfd[0], buffer, sizeof(buffer))>0) { printf("%s", buffer); } wait(&rv); fprintf(stderr,"%s exited with value %d\n", cmd, rv); } return 0; } #### The filedescriptors are: 4 6 This is the child This is the parent this is a message ./my_prog.pl exited with value 0