Where do stdout and stderr go when curses is active?
import curses, sys
def test_streams():
print "stdout"
print >>sys.stderr, "stderr"
def curses_mode(stdscr):
test_streams()
test_streams()
curses.wrapper(curses_mode)
Actual output is
stdout
stderr
Expected output is
stdout
stderr
stdout
stderr
entering, and then exiting curses mode with no change to the final text shown in the terminal.
By default, stderr is typically connected to the same place as stdout, i.e. the current terminal.
stdout − It stands for standard output, and is used to text output of any command you type in the terminal, and then that output is stored in the stdout stream. stderr − It stands for standard error. It is invoked whenever a command faces an error, then that error message gets stored in this data stream.
Activating curses saves the terminal text screen's current contents and clears said screen; exiting curses restores the screen's contents (tossing away whatever's been put on screen during the reign of curses itself). Try with this variant of your code and you'll see better what's happening:
import curses, sys, time
def test_streams(wot):
print wot, "stdout"
print >>sys.stderr, wot, "stderr"
def curses_mode(stdscr):
test_streams("wrap")
time.sleep(1.0)
test_streams("before")
curses.wrapper(curses_mode)
test_streams("after")
You'll note the wrap stderr
on the screen for a second (during the sleep) -- it's overwritten the stdout part -- then it disappears and you see the four before and after lines on the now-quiescent screen (you can add other sleeps to follow what's happening in even more details, if you care).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With