How to clear the DOS screen through java program

how to clear the DOS screen through java program

Just some Friday fun. Use the telnet program that comes with Windows and supports VT escape sequences.
import java.io.*;
import java.net.*;
public class AutoTelnet {
     private static Socket s;
     public static void main(String[] args) throws Exception {
          Thread t = new Thread() {
               @Override public void run() {
                    try {
                         s = new ServerSocket(5555).accept();
                    } catch (IOException ex) {
                         ex.printStackTrace();
          t.start();
          Process p = new ProcessBuilder("cmd", "/C", "start", "telnet", "127.0.0.1", "5555").redirectErrorStream(true).start();
          t.join();
          PrintStream ps = new PrintStream(s.getOutputStream());
          ps.println("Screen will be cleared in 5 seconds");
          ps.println("5");
          Thread.sleep(1000);
          ps.println("4");
          Thread.sleep(1000);
          ps.println("3");
          Thread.sleep(1000);
          ps.println("2");
          Thread.sleep(1000);
          ps.println("1");
          Thread.sleep(1000);
          ps.println("\u001b[2J");
          Thread.sleep(5000);
}

Similar Messages

  • Please tell me e code to clear the dos screen in my program

    please sir/mam if u colud plz elp me to know hoe th clear the dos screen in java and I had tried the code i.e.
    Runtime.getRuntime.exec("cls")
    but it did not worked so plz help me out
    u can mail me at [email protected]

    class ClearScreen
         public static void main(String[] args)
              //  The following code needs ansi.sys added to config.sys
              //  DEVICE=C:\WINDOWS\COMMAND\ANSI.SYS
    //          char esc = 27;
    //          String clear = esc + "[2J";
    //          System.out.print(clear);
              //  this will work in all cases
              for (int i = 0; i < 250; i++)
                   System.out.println();
    }

  • How to execute MS DOS command through Java program???

    Dear Sir,
    I want to run a MS-DOS command through my Java program. I have tried "Dir" command but no other command which takes command line args doesn't work at all. Please help.
    import java.io.*;
    class CommandPrompt
         public static void main(String[] args)
              try
                   File file = new File("C:/Temp/Java");
                   String[] cmd = {"command.com","/c","md folder"};
                   String[] envp = {""};
                   Process m;
                   String s = "";
                   m = Runtime.getRuntime().exec(cmd,null,file);
                   BufferedReader buf = new BufferedReader(new InputStreamReader(m.getInputStream()));
                   while ((s = buf.readLine())!=null)
                        System.out.println(s);
              catch (Exception ex)
                   System.out.println("Exception is "+ex);
                   ex.printStackTrace();

    1. This forum is for Swing-related issues only. This question should be posted to the "Java Programming" forum.
    2. Please enclose your sample code in code blocks; it's much easier to read that way. See here for how it's done: http://forum.java.sun.com/faq.jsp#messageformat
    3. Please provide more information, like what error messages you got and what OS you're running. For instance, if you're running WinXP, Win2k or NT4, your command processor should be "cmd.exe", not "command.com". When I made that change, your program worked for me.

  • Clearing the DOS Window in Java

    hi
    I want to clear the dos screen using java.
    I saw 2 solutions on the net(given below) , but both did not work. Can someone advise how I can go about doing this ? I'm
    working on Windows2000.
    Thanks in advance.
    Seema
    1. char esc = 27; // ESC code
    String clear = esc + "[2J" // note case
    System.out.print(clear); // Dos screen should be cleared
    2. Runtime.getRuntime().exec( "cmd.exe /c cls" ) ;

    The escape code approach would only work on DOS windows that are processing ANSI escape sequences. This is something people used to enable all the time back in the pre-Windows days, since it was the only way to do things like clearing screens, setting colours, drawing menus out of text characters, etc. Ansi.sys still exists, at least on Win98 (not sure about NT, 2000, etc.). If you troll through the Microsoft web site or hunt down old books on DOS, you'll be able to find out how to set it up and use it.

  • How to connect iseries green screen from java program

    how to connect iseries green screen from java program to get the data in the DB files ,here the DB is DB2/400

    Just some Friday fun. Use the telnet program that comes with Windows and supports VT escape sequences.
    import java.io.*;
    import java.net.*;
    public class AutoTelnet {
         private static Socket s;
         public static void main(String[] args) throws Exception {
              Thread t = new Thread() {
                   @Override public void run() {
                        try {
                             s = new ServerSocket(5555).accept();
                        } catch (IOException ex) {
                             ex.printStackTrace();
              t.start();
              Process p = new ProcessBuilder("cmd", "/C", "start", "telnet", "127.0.0.1", "5555").redirectErrorStream(true).start();
              t.join();
              PrintStream ps = new PrintStream(s.getOutputStream());
              ps.println("Screen will be cleared in 5 seconds");
              ps.println("5");
              Thread.sleep(1000);
              ps.println("4");
              Thread.sleep(1000);
              ps.println("3");
              Thread.sleep(1000);
              ps.println("2");
              Thread.sleep(1000);
              ps.println("1");
              Thread.sleep(1000);
              ps.println("\u001b[2J");
              Thread.sleep(5000);
    }

  • How to create an Oracle DATABASE through Java Programming Language.. ?

    How to create an Oracle DATABASE through Java Programming Language.. ?

    Oracle database administrators tend to be control freaks, especially in financial institutions where security is paramount.
    In general, they will supply you with a database, but require you to supply all the DDL scripts to create tables, indexes, views etc.
    So a certain amount of manual installation will always be required.
    Typically you would supply the SQL scripts, and a detailled installation document too.
    regards,
    Owen

  • Changing the ip address of the local machine through java program

    Hi all,
    I want to change the ip address of the machine in windows and linux through java program. Iam not aware that wheather this is possible or not. If possible pls help me.
    Regards
    Bhaskar

    I'm always surprised by the weird things that developers find they need to do!

  • How to call the DLL functions through Java

    Hello,
    I have already got a VC++ generated DLL. It has serveral functionalities. I need to call those functions from my Java Application. Now i know that it can be possible only through writing Java JNI Interfaces.
    Everywhere i only see they give an example where in they tell to create an DLL. Now how do i will call if an DLL is ready and exists.
    If anyone can give an example then it will be very helpful to me. Please mail me at [email protected] .
    Thank you
    vvpatro

    You can't call functions in an arbitary DLL form Java. You need to use JNI to produce a 'wrapper' DLL that maps Java methods to the methods in the target DLL. The purpose of the wrapper is to allow type conversion between Java types and C/C++ types. The complexity of this task depends largely on the types used in th target DLL. If the targer DLL uses only primitive types such as char, byte, int, long, string, the translation is simple and the wrapper DLL will be 'thin'. If however, the target DLL passes arrays and objects, or employs callbacks, these more work to do, and the wrapper will be correspondingly 'thicker'.
    Hope this helps.

  • How to pass the report parameters through java not by using URL

    Hello...
    I have an oracle App. Server 10g with report service
    I can the report using the URL :
    http://host:Port/rwservlet/report=....
    and passing the report parameters ...
    But is there any way to call the report by pdf format and passing the parameters from java without using the url ???

    thank you shahcsanjay for your reply
    but I think that web.showDocument can not be used by ordinary java web application ..
    I think it can be used only with with "oracle forms" Am I right ?
    If no can you please tell me where can I find a useful document about how to use web.showDocument ...
    thanks again
    Saleem

  • Clearing the console screen

    I am tring to clear the console screen using java like clrscr() function in c..( cls command in Dos).
    Can anyone help me out.

    Hi ,
    Try this code.
    char esc = 27;
    String clear = esc + "[2J";
    System.out.print(clear);
    And this line must be inside the config.sys:
    device=c:\windows\command\ansi.sys
    Hope this helps.
    Roopasri Vittal
    Developer Technical Support
    Sun Microsystems
    http://sun.com/developers/support

  • Accessing RUN through java programming

    Sir,
    i need to develop a java application t access "run" in start menu.How can i access the run menu through java programming.?I want to run the program in the run command when we input command through the java program..please help me..if you have the code palese send it tio me please..........

    But I cant access the drives for eg: I wrote c:\programfiles as input but i got an exception like this
    error=3
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
    at java.lang.ProcessImpl.start(ProcessImpl.java:30)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:451)
    at java.lang.Runtime.exec(Runtime.java:591)
    at java.lang.Runtime.exec(Runtime.java:429)
    at java.lang.Runtime.exec(Runtime.java:326)
    at ex.main(ex.java:10)
    how can correct this error...

  • How to clear the screen in java?

    Hi,
    How to clear the screen in java without using any loops?
    Thanks

    Just paint with your background color to let the old paintings vanish.

  • How to clear the Residual & partial payment through app

    Hi Experts,
    How to clear the Residual and partial payment through app in accounts payable i tried but i am not getting the out put so plz clarify the my question and any other configuration for that give answer with example...
    Thanks for advance
    Regards,
    Nivas99

    Hi Nivas,
    Partial payment is possible throw app but not possible residual payment.
    Partial payment u create a payment request p as a special indication u can try.
    I hope this is help full u.
    regards,
    venkatesh

  • How to clear the values from a Tab Screen.

    Hi,
    I have created Two Tab in my report by using the below mentioned code.
    SELECTION-SCREEN BEGIN OF SCREEN 200 AS SUBSCREEN.
    SELECTION-SCREEN BEGIN OF BLOCK BR_ACB WITH FRAME TITLE TEXT-502.
    PARAMETERS: P_VATNUM   TYPE T001-STCEG,
                 P_NAME     TYPE T001-BUTXT,
                 P_STREET   TYPE rfpdo-KQSUSTRAS,
                 P_CITY     TYPE rfpdo-KQSUPADD02,
                 P_CNTRY    TYPE rfpdo-ALLGINLD.
    SELECTION-SCREEN END OF   BLOCK BR_ACB.
    SELECTION-SCREEN END OF SCREEN 200.
    SELECTION-SCREEN BEGIN OF SCREEN 201 AS SUBSCREEN.
    SELECTION-SCREEN BEGIN OF BLOCK br4 WITH FRAME TITLE text-503.
    PARAMETERS: P_IDLU    TYPE LU_IDCODE,
                 P_VATNU   TYPE LU_VATNUM,
                 P_DESIG   TYPE LU_DESIGNATION,
                 p_telf  LIKE rfpdo-asldtelf.       "Telefonnummer
    SELECTION-SCREEN END OF BLOCK br4.
    SELECTION-SCREEN END OF SCREEN 201.
    SELECTION-SCREEN BEGIN OF TABBED BLOCK tabb1 FOR 8 LINES.
    SELECTION-SCREEN TAB (15) tabs1 USER-COMMAND ucomm1 DEFAULT SCREEN 200.
    SELECTION-SCREEN TAB (15) tabs2 USER-COMMAND ucomm2 DEFAULT SCREEN 201.
    SELECTION-SCREEN END OF BLOCK tabb1.
    INITIALIZATION.
      tabs1 = text-500.
      tabs2 = text-501.
    Problem I am facing here is when report loads the screen once and I am filling all the valuse in the Tab Screen 200 and 201 and executing the report and when I am reloading any other variant then it is not clearing the valuse present in the Tab Screen 200 and 201.
    Can any buddy help me regarding this to clear the Tab Screen 200 and 201.
    Thanks and best regards,
    Niteesh Rai

    Hi Niteesh,
    I have tested the scenario which you have mentioned above,  Its working fine for me.
    I have filled all the values in screen 200 and 201 as well and saved it as variant Test1, and again
    I have filled all the values in screen 200 and 201 as well and saved it as variant Test2.
    When I am changing the variants from Test1 to Test2 and vice versa.  I displaying their respective data as well.
    Regards,
    Md Ziauddin.

  • Execute dos commands through java

    Hi,
    Im trying to execute dos commands through java like
              try {
                   java.lang.Runtime.getRuntime().exec("cmd /c cls");
              }catch(IOException e){
                   System.out.println(e.getMessage());
              }Not sure if its possible? however
    open notepad would work
              try {
                   java.lang.Runtime.getRuntime().exec("notepad");
              }catch(IOException e){
                   System.out.println(e.getMessage());
              }Im trying to execute a cls commands to clear screen but without luck.

    The question is, which shell do you want to clear?
    I don't really know, but it could be that Runtime.exec executes its command in a new shell window...

Maybe you are looking for