Changing around IO redirection

I've changed all the IO redirection stuff to use dup2 to replace file descriptors as atomically as is possible. Perhaps it will work on OS X now?