Why are you rewinding stdin and stdout?