View Single Post
Old Oct 9th, 2005, 10:36 AM   #18
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Swimmfree200 , the JVM can write to the screen can't it? Good becase that's all the terminal clear screen code needs.

Thanks for the insight.

[php]
import java.io.*;

public class RunCommand {

public static void main(String args[]) {

String s = null;

Process clear;

try {
clear = Runtime.getRuntime().exec("cls");

BufferedReader stdOut = new BufferedReader(new InputStreamReader(clear.getInputStream()));

while((s = stdOut.readLine()) != null)
System.out.print(s);

System.exit(0);
}
catch (IOException e) {
try {
clear = Runtime.getRuntime().exec("clear");

BufferedReader stdOut = new BufferedReader(new InputStreamReader(clear.getInputStream()));

while((s = stdOut.readLine()) != null)
System.out.print(s);

System.exit(0);
} catch(IOException d) {
System.out.println("Get a real machine:");
d.printStackTrace();
System.exit(-1);
}
}
}
}
[/php]

That program clears the screen or throws an IOException on any windows or unix machine with the commands "cls" or "clear" respectively.
__________________


Last edited by tempest; Oct 9th, 2005 at 10:48 AM.
tempest is offline   Reply With Quote