9

Could anyone tell me if it's possible to clear console in intellij-idea and how?

So far I have tried:

System.out.print("\033[H\033[2J");
System.out.flush();

and:

Runtime.getRuntime().exec("clear");

but any of those did work.

I'm using Intellij-idea ultimate 2017 2.4 and Linux Mint.

Arnav Borborah
  • 10,781
  • 6
  • 36
  • 77
  • Possible duplicate of [Java: Clear the console](https://stackoverflow.com/questions/2979383/java-clear-the-console) – Anton Balaniuc Sep 15 '17 at 14:54
  • @AntonBalaniuc If any of those suggestions worked for me except printing new line 50x i would have not created this topic – stilltryingbutstillsofar Sep 15 '17 at 14:58
  • 1
    Write a plugin: https://stackoverflow.com/questions/46102201/is-it-possible-to-clear-the-console-tab-during-runtime-in-intellij-with-java#comment79167189_46102201 – Meo Sep 15 '17 at 15:01
  • The best thing would be to implement it into https://github.com/krasa/GrepConsole and send a pull request. – Meo Sep 15 '17 at 15:10

4 Answers4

3

Use Grep Console plugin for clearing it when it matches some output.

Meo
  • 11,291
  • 5
  • 44
  • 51
0

I don't believe you can, think of that window as a log file.

BTW, why would you want to clear that?

cristianoms
  • 2,936
  • 2
  • 24
  • 27
0

"Right" click over the console and select "clear all"

enter image description here

jbmilgrom
  • 15,815
  • 5
  • 23
  • 22
0

IntelliJ IDEA console is not a real terminal, so there is no command to clear it from your Java code.

See the issue here.

Try run your application in other terminal, then you can make a function like this:

public static void ClearConsole(){
    try{
        String operatingSystem = System.getProperty("os.name") //Check the current operating system
          
        if(operatingSystem.contains("Windows")){        
            ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "cls");
            Process startProcess = pb.inheritIO.start();
            startProcess.waitFor();
        } else {
            ProcessBuilder pb = new ProcessBuilder("clear");
            Process startProcess = pb.inheritIO.start();

            startProcess.waitFor();
        } 
    }catch(Exception e){
        System.out.println(e);
    }
}