Reputation: 3
Hello Stack Overflow !
I am currently working on a Java program that is essentially a digitized character sheet for a Dungeons and Dragons style adventure. This program makes extensive use of a ClearScreen()
method that I made, which makes use of a process builder, as shown below:
new ProcessBuilder( "cmd", "/c", "cls" ).inheritIO().start().waitFor();
Recently I learned that one of my players has a Mac, and as such I need to translate the cmd
command that this process builder uses into its Mac/Linux equivalent. I already did some research beforehand, and managed to construct the following ProcessBuilder:
new ProcessBuilder("terminal","","clear");
However, I don't know what the equivalent of /c
would be, which is an argument that causes CMD to close after the command is executed. Thus, I would like help in filling in the missing argument (or maybe a more efficient means of achieving the same result). Thank you in advance!
(also, my apologies in advance for any misused terms ^^; I'm still learning how to program in Java, and I've never owned a Mac so I'm kind of stumbling around in the dark here. I should clarify that the program runs out of the Windows command-prompt interface, using a .bat
file called rubberglove.bat
.)
Upvotes: 0
Views: 82
Reputation: 123410
On MacOS (and GNU/Linux, and *BSD), clear
is a stand-alone program that doesn't require the services of an additional shell or program. Just call it directly:
new ProcessBuilder("clear").inheritIO().start().waitFor();
Or simply print the equivalent ANSI escape codes to clear the screen and set the cursor to the origin. This works on all standard Unix-like terminals, and is essentially what clear
ends up doing:
System.out.print("\u001B[H\u001B[J");
Upvotes: 1