fixed IOError when stdout piped to programs that close stdout