[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Redirect stderr to ncurses window
From: |
Jeff Barnes |
Subject: |
Redirect stderr to ncurses window |
Date: |
Mon, 23 May 2011 09:04:10 -0700 (PDT) |
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]);
while(isRunning && read(outp[0], buf, sizeof(buf)-2)) {
len = strlen(buf);
buf[len+1] = '\n';
g_mutex_lock(curses_mutex);
wprintw(console.msgw, buf);
wrefresh(console.msgw);
g_mutex_unlock(curses_mutex);
memset(buf, 0, strlen(buf)+1);
}
}
- Redirect stderr to ncurses window,
Jeff Barnes <=