Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
stderr redirect to file
#1
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
Reply
#2
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
Reply
#3
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [subprocess] Why stdout sent to stderr? Winfried 3 489 Jan-26-2024, 07:26 PM
Last Post: snippsat
  redirect STDIO in the Python code Skaperen 6 1,301 Jul-05-2023, 12:23 AM
Last Post: Skaperen
  changing stdout and stderr Skaperen 4 2,711 Dec-02-2020, 08:58 PM
Last Post: Skaperen
  Cannot redirect print to a file tester_V 3 2,529 Sep-11-2020, 12:21 AM
Last Post: tester_V
  connot write to sys.stderr anne 7 2,884 Jul-31-2020, 12:39 AM
Last Post: millpond
  redirect url_for passing arguments with the url Leon79 1 1,658 Jul-09-2020, 05:20 PM
Last Post: Leon79
  Redirect to __stdout__ fails in IDLE shell Pavel_47 1 1,969 Apr-13-2020, 05:13 PM
Last Post: deanhystad
  how to output to stderr from inside a generator? Skaperen 2 1,842 Mar-03-2020, 03:17 AM
Last Post: Skaperen
  Redirect to file vndywarhol 1 2,310 Aug-23-2018, 11:01 AM
Last Post: DeaD_EyE
  Python redirect users to another url after form post blsturgeon 5 18,886 Jun-28-2018, 11:53 PM
Last Post: gontajones

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020