'Clearing console in Intellij-idea
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.
Solution 1:[1]
Use Grep Console plugin for clearing it when it matches some output.
Solution 2:[2]
I don't believe you can, think of that window as a log file.
BTW, why would you want to clear that?
Solution 3:[3]
Solution 4:[4]
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);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Meo |
| Solution 2 | cristianoms |
| Solution 3 | jbmilgrom |
| Solution 4 | Jose Galdamez |

