Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2007

Tip: Looking for answers? Try searching our database.

How clear console using java

Thread view: 
AimsLife - 07 Sep 2007 06:03 GMT
Hi,

I am using Jdk1.5 for development. I need to clear java console after
printing 100 lines of test on console. I tried below code it is
working for compiling java (.java) but it through exception
(IOException).

       try {
           Process dir = Runtime.getRuntime().exec("cls");
           BufferedReader bufr_in = new BufferedReader(new
InputStreamReader(dir.getInputStream()));
           String readLine = "";
           if( ( readLine = bufr_in.readLine() ) != null )
           {
             System.out.println(readLine);
             while( ( readLine = bufr_in.readLine() ) != null )
                 System.out.println (readLine);
           }

       } catch (IOException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }

Above code throws exception at run time.

java.io.IOException: Cannot run program "cls": CreateProcess error=2,
The system cannot find the file specified
   at java.lang.ProcessBuilder.start(Unknown Source)
   at java.lang.Runtime.exec(Unknown Source)
   at java.lang.Runtime.exec(Unknown Source)
   at java.lang.Runtime.exec(Unknown Source)
   at atm.Driver.main(Driver.java :52)
Caused by: java.io.IOException: CreateProcess error=2, The system
cannot find the file specified
   at java.lang.ProcessImpl.create(Native Method)
   at java.lang.ProcessImpl.<init>(Unknown Source)
   at java.lang.ProcessImpl.start(Unknown Source)
   ... 5 more

Please guide me, where I am going wrong thing? And how I can clear
console through my code?

Regards,
-aimslife
manishsw@gmail.com - 07 Sep 2007 09:04 GMT
> Hi,
>
[quoted text clipped - 41 lines]
> Regards,
> -aimslife

http://www.rgagnon.com/javadetails/java-0469.html
Roedy Green - 07 Sep 2007 14:55 GMT
> need to clear java console after
>printing 100 lines of test on console.

see http://mindprod.com/jgloss/console.html

You just emit a string of linefeeds.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Roedy Green - 07 Sep 2007 14:56 GMT
>java.io.IOException: Cannot run program "cls": CreateProcess error=2,

cls is not a program. It is a an internal command to the command
processor.

You must spawn a command processor with cls as a parameter. However,
than is not a platform independent way to solve you problem.

see http://mindprod.com/jgloss/exec.html
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

AimsLife - 10 Sep 2007 06:59 GMT
Thanks, all!

Regards,
-aimslife
.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.