/********************************************************* * * pipe.c * * 4/15/04 Jeff Ondich * *********************************************************/ #include #include #include #include #include #include #include int main() { int pid; int fd[2]; if( pipe( fd ) < 0 ) { perror( "Trouble creating pipe.\n" ); exit( 1 ); } pid = fork(); if( pid < 0 ) { perror( "Trouble forking.\n" ); exit( 1 ); } if( pid != 0 ) { close( fd[0] ); if( dup2( fd[1], STDOUT_FILENO ) == -1 ) perror( "Trouble redirecting stdout." ); close( fd[1] ); execlp( "cat", "cat", "moose.txt", NULL ); perror( "We shouldn't get here." ); } else { close( fd[1] ); if( dup2( fd[0], STDIN_FILENO ) == -1 ) perror( "Trouble redirecting stdin." ); close( fd[0] ); execlp( "wc", "wc", NULL ); perror( "Shouldn't get here." ); } return 0; }