Python Forum

Full Version: stderr redirect to file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to redirect stderr to a file, and I've read the numerous posts here, but it's not working for me on a Pi or on my Win laptop.
Hoping someone will see what's wrong.

Using IDLE -

On Pi, the file is written but is empty, and stderr (traceback - /0) wasn't written to the IDLE shell....

On Win, the file is written but is empty, and stderr (traceback - /0 ) still appears in the IDLE shell.


import sys
import time

sys.stderrr = open('errout.txt', 'w')
print("stderr redirected now.")

i = 1/0
You've misspelled sys.stderr. If that is corrected, it should work.

Output:
$ python3 redir.py stderr redirected now. $ cat errout.txt Traceback (most recent call last): File "redir.py", line 7, in <module> i = 1/0 ZeroDivisionError: division by zero
Wow.... that's what happens when you're cutting and pasting (the original error). Amazing what another set of eyes can do.

THANKS !!! Smile Smile Smile Smile Smile Smile