Where do stdout and stderr go when in curse mode?

Where do stdout and stderr go when curses are 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 conclusion

 stdout stderr 

Update0

Expected Result

 stdout stderr stdout stderr 

and then exit the curse mode without changing the final text displayed on the terminal.

+6
python ncurses curses
source share
1 answer

Activation of curses saves the current contents of the screen text screen of the terminal and clears the specified screen; exiting curses restores the contents of the screen (discards everything that was placed on the screen during the reign of the curses themselves). Try this version of your code and you will see what happens:

 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 will notice a wrap stderr on the screen for a second (during sleep) - it overwrites the stdout part - then it disappears and you see the four lines before and after the screen is now inactive (you can add other sleep to keep track of what is happening in more detail, if you're interested).

+5
source share

All Articles