I think the null pointer exception is occurring from the printStream.println() call, rather than the exec() call. You haven't initialized "printStream", so when the error from that exec() command is thrown (which is that "cls" is not a program, by the way), the catch statement is throwing the exception out to main().
To execute a command, you have to use "cmd /c ". However, if you are expecting that command to clear the command window in which you are running your program, it will not. Runtime.getRuntime().exec() creates a new separate process.
Ezzaral
Posting Genius
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
In short, you can't clear the console without system specific calls. You can write a bunch of blank lines to scroll everything to a point it looks clear, but that's about all without "workaround hacks".
If you want full control of the screen that you are running in, you should make the application a GUI application.
Ezzaral
Posting Genius
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
and you shouldn't even TRY to control the console. You do NOT own the console, NEVER assume you're the only thread/process writing to it.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337