File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "why do i get an exception?" Watch "why do i get an exception?" New topic

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

Joined: Jul 08, 2003
Posts: 24199

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
I agree. Here's the link:
subject: why do i get an exception?
It's not a secret anymore!