File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply 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: 24054
    
  13

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: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: why do i get an exception?
 
Similar Threads
how to detect the operating system in java
comparing System.getProperty to string
Clearing DOS screen in Java
Getting Computer Name using JNI
HttpServletResponse obj lost after using System.getProperty