#include #include main(int argc, char **argv){ int mypipe[2],pid; if(argc < 3){ printf("usage: %s cmd1 cmd2\n",argv[0]); exit(0); } pipe(mypipe); pid=fork(); if(pid<0){ printf("we encounted a fork error\n"); exit(1); } if(pid == 0){ /* we are the child */ close(mypipe[0]); /* close the read end of the pipe */ close(1); /* closes stdout */ dup(mypipe[1]); /* duplicate write end of pipe on stdout */ close(mypipe[1]); /* close write end of pipe */ system(argv[1]); } if(pid > 0){ /* we are the parent */ close(mypipe[1]); /* close write end of pipe */ close(0); /* close stdin */ dup(mypipe[0]); /* duplicate read end of pipe in stdin */ close(mypipe[0]); /* close read end of pipe */ system(argv[2]); } }