I\'d like to write a simple program using ncurses for displaying some data. I would then like for the program to write to stdout in such a way that I can then use a pipe (|
By default, curses writes to the standard output, which is where your pipe goes. But there are two different initialization functions for curses: initscr
and newterm
. The latter lets you do what was asked, like this:
#include
#include
int main(int _argc, char ** _argv)
{
newterm(NULL, stderr, stdin); /* Start curses mode */
printw("Hello World !!!"); /* Print Hello World */
refresh(); /* Print it on to the real screen */
getch(); /* Wait for user input */
printf("GOT HERE");
endwin(); /* End curses mode */
printf("GOT HERE");
return 0;
}
Further reading: manual page for newterm and initscr.