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]);