Moved stdout redirection to pure Python.