简体   繁体   中英

eclipse ncurses and xterm, unknown characters printed

I faced with Error opening terminal: unknown. with ncurses and Eclipse Luna.

So installed xterm and add TERM=xterm in Run/Debug Configurations > Environment.

Now, when I run following simple "Hello World" app, some strange characters printed in the Eclipse console:

在此处输入图片说明

Code:

#include <stdio.h>
#include <ncurses.h>

int main() {
    initscr();                 /* Start curses mode     */
    printw("Hello World !!!"); /* Print Hello World    */
    refresh();                 /* Print it on to the real screen */
    getch();                   /* Wait for user input */
    endwin();                  /* End curses mode    */

    return 1;
}

What are these characters? And how to remove them?

These characters are what initscr() outputs to do its job.

A terminal knows not to show these characters and interpret them in a special way. Since the Eclipse console is not a terminal, it has not a faintest idea.

If you want your program to work in both terminals and non-terminals, you need to check whether your standard output is a terminal, and avoid using ncurses -specific functions if it is not. See man isatty .

If you only need your program to work in terminals, just don't use Eclipse console. See this question and its answer for set-up instructions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM