Possible Duplicate:
Writing my own shell… stuck on pipes?
I'm building a program with shell like functionality, and I was wondering how to perform a piping operation. So when the system executes program1 arg | tee output-file the system will connect the stdin from the tee to the stdout from program1 as well as catching any stderr and the final stdout.