aspose file tools*
The moose likes Java in General and the fly likes why do i get an exception? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "why do i get an exception?" Watch "why do i get an exception?" New topic
Author

why do i get an exception?

Damien Howard
Ranch Hand

Joined: Apr 01, 2003
Posts: 456


I am running this on a windows machine. It goes into the windows clause and it assigns cls to my var, but I get an IOException and my cmd window is not cleared. Does anyone know why?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Probably because here's no "cls.exe"; it's a command built into the shell. You'd have to exec something like "cmd /E cls" -- i.e., run the shell, and tell it to execute the cls command.

But -- and this is a big "but" -- that shell wouldn't be connected to a terminal window; it takes input from the Java process. So the cls command would have no effect!

There are two ways to clear a terminal window from a Java program: first, send a (platform dependent) escape sequence to the terminal to clear it (Google for "ANSI escape codes" to learn more) or just print a bunch of blank lines to make the contents of the screen scroll away!


[Jess in Action][AskingGoodQuestions]
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

Navigate yourself around pitfalls related to the Runtime.exec() method
 
 
subject: why do i get an exception?