bug-ncurses
[Top][All Lists]
Advanced

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

Re: Redirect stderr to ncurses window


From: Thomas Dickey
Subject: Re: Redirect stderr to ncurses window
Date: Mon, 23 May 2011 16:56:34 -0400 (EDT)

On Mon, 23 May 2011, Jeff Barnes 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?

I'm locking down all ncurses function calls with the same mutex.

Am I "barking up the wrong tree?"

Thanks for any help.

void
stderr_thread_func(void *data) {
 int outp[2], old, len;
 char buf[1024] = {0};
 old = dup(stderr);
 if (pipe(outp) != 0) {
   g_mutex_lock(curses_mutex);
   wprintw(console.msgw, "Pipe failed\n");
   wrefresh(console.msgw);
   g_mutex_unlock(curses_mutex);
   return;
 }
 dup2(outp[1], stderr);
 close(outp[1]);

dup/dup2 take an integer parameter, e.g., something (in this context) like fileno(stderr). compiler warnings are useful for finding these problems.

I added code to dialog recently (the dlg_popen function in prgbox.c)
which does something like this.

--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net



reply via email to

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