29

If I

System.out.print("something\r");

at console, I have cursor back at the beginning of line, and finally after

System.out.print("something\r");
System.out.print(" any\r");

I have

 anything

typed.

But at Eclipse console I get

something
 anything

as if it treated \r as CR/LF.

How can I setup this?

Dims
  • 47,675
  • 117
  • 331
  • 600
  • 11
    Seems like an unresolved bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=76936 –  Feb 09 '13 at 23:02
  • 2
    While I can understand the use of this, I ask why you need it to work in Eclipse. It might be inconvenient, but at some point I would imagine that you will just have to test it in a console window, presumably its final execution place anyway. Eclipse is capable of running external programs for testing - I have to do it all the time since my program runs via .bat file. (Sorry I can't be of more help.:/ ) – Tustin2121 Feb 12 '13 at 17:06

4 Answers4

20

As Nishant already pointed out in the comments, you've found a bug here.

This bug initially was reported in 2004 (>9 years ago!?!!) and this bug seems not to be fixed very soon (or ever). I tested it on several Eclipse version, even on Eclipse Juno SR2, and the bug is still there.

poitroae
  • 21,129
  • 10
  • 63
  • 81
13

The bug is fixed by now (Eclipse 2020-03). Just go to

Window ➺ Preferences ➺ Run/Debug ➺ Console

and make sure that both checkboxes

Interpret ASCII control characters

and

Interpret Carriage Return (\r) as control character

are enabled.

John McClane
  • 3,498
  • 3
  • 12
  • 33
3

It finally seems to be fixed in Mars!

Version: Mars Release (4.5.0)
Build id: 20150621-1200
Used Java: jre1.8.0_60

Your code

public class Main {

    public static void main(String[] args) {
        System.out.print("something\r");
        System.out.print(" any\r");
    }
}

Output

 anything
das Keks
  • 3,723
  • 5
  • 35
  • 57
0

Move the mouse pointer into the console area, click on the right mouse button, a popup menu opens. Click on "Preferences..." item. Check "Interpret Carriage Return (\r) as control character" box. Click on "Apply and Close" button.

Jeff
  • 1