Added struct pipe functions for duping.

Added pipe_dup_readable_fd(), pipe_dup_writable_fd(), pipe_dup_to_stdin(),
pipe_dup_to_stdout() and pipe_dup_to_stderr().

Replaced uses of dup2() in main.c with appropriate struct pipe function.