-1

I am using Eclipse Oxygen.3A for development with C, and the operating system on which I'm running is Fedora 28. The C project that I am attempting to debug contains multiple instances of system("clear");. When I would compile and run the application from Fedora's local terminal, any calls to system() would behave normally. After using Eclipse's debug tools to "step over" the statement and execute it, the launch terminal printed garbage (see screenshot below). The same output is printed every time the program is run.

Eclipse debug console printing garbage after <code>system("clear")</code> is executed

I created a new project with the same environment variables which isolated that statement, but received the same result (see screenshot below). The only environment variable present in either launch configuration is TERM which is set to xterm-256color (the value printed by Fedora's local terminal when given the input echo $TERM). I couldn't find any results online pertaining to this particular issue, and don't understand how the function is implemented during compilation.

Separate "Test" project producing the same result

Contents of source file in Test project: #include

int main(void) {
    system("clear");
    return 0;
}

Generated output: '[ESC]' + "[3J" + '[ESC]' + "[H" + '[ESC]' + "2J"

Note: Imagine this string concatenated. I couldn't write the output literally because StackOverflow is unable to represent the "escape" character.

My knowledge of Linux, bash and the tools provided by GNU is fairly limited, so let me know if any more information on this case would be helpful along with how to obtain it. Also, any feedback on how I could improve this post is welcome.

  • Note, most users here prefer textual information to be provided (also) in textual form. Some even downvote otherwise. (I did not though.) – Yunnosch Dec 12 '18 at 06:41
  • Please avoid the impression that your "follow up" is a separate question, making two questions in one post. Users here might consider a package of two questions in one to be "too broad". – Yunnosch Dec 12 '18 at 06:43
  • That display doesn't appear to understand terminal control strings. (It might not use a terminal or pseudo terminal at all, just capture the program's standard output via a pipe and display it in a text widget.) – Shawn Dec 12 '18 at 06:47
  • 1
    It's generally considered poor practice to try to clear a terminal display anyways. – Shawn Dec 12 '18 at 06:49
  • @Yunnosch Thanks for all of your edits and feedback. If there's anything else that I you think I should change or make note of, feel free to let me know. –  Dec 12 '18 at 20:33
  • @Shawn Thanks for letting me know. I'll keep that in mind. –  Dec 12 '18 at 20:35

1 Answers1

2

Well, everything works as expected here.

Dinosaurs can remember the time where we used serial terminals. In those old days, we all knew that screen formatting was done with special control sequences. Unix-Linux terminals (console, xterm and friends) still use that good old terminfo interface, where the screen capabilities and special sequences are declared in the terminfo database with the key given by the TERM environment variable.

According to your eclipse image, clear just sent the sequence Esc [ 3 J Esc [ H Esc [ 2 J. A terminal would clear when it receives that, but Eclipse output window just displays it to help the developper to know what control characters were send. You can even see the 1B ascii code of the Esc control character in the small squares when you look at the image in full resolution...

That means that there is nothing to do here: you asked the program to send the clear escape sequence, and Eclipse output window confirms it was actually send.

Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252