[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Redirect stderr to ncurses window

From: Stephan Beal
Subject: Re: Redirect stderr to ncurses window
Date: Mon, 23 May 2011 18:15:45 +0200

On Mon, May 23, 2011 at 6:04 PM, Jeff Barnes <address@hidden> wrote:
I've seen posts and blogs advising against this, but I need to grab debug output from a library and print it to an ncurses window. I've tried code like the following, but it doesn't work and corrupts the terminal window. What do I have to do to grab the library stderr output and wprintw it to a WINDOW?

If you're able to use C++ and your application only uses std::cerr to output to stderr (as opposed to fprintf() or similar) then it's really easy to redirect stderr (or stdout, or any std::ostream) to an arbitrary WINDOW. See the nc_window_streambuf class in this these files:


It can be used like this:

nc_window_streambuf buf( myWindow, std::cerr );

This swaps out the stream's buffer object for the lifetime of 'buf'. When buf goes out of scope (or is otherwise destructed) then the target stream's buffer is re-set to its old state.

i've been using that approach for years to capture std::cout and std::cerr to _javascript_-scripted curses windows. When curses mode is shut down the "interceptor buffer" is killed off and cout/cerr return to their normal behaviours.

----- stephan beal

reply via email to

[Prev in Thread] Current Thread [Next in Thread]