You are on page 1of 4

Forums.Oracle.

com Forum Home Java Essentials Java Programming Thread: how to clear the DOS screen through java program Welcome, Guest Sign In / Register Guest Settings Search FAQ This question is answered. Helpful answers available: 5. Correct answers available: 1. Reply to this Thread Back to Thread List Permlink y: jschell 878207 Reply to this Thread Back to Thread List Search Forum Search Forum

Replies: 8 - Pages: 1 - Last Post: 12-Aug-2011 15:27 Last Post B

Posts: 3 Registered: 08/09/11 how to clear the DOS screen through java program Posted: 10-Aug-2011 01:41 Click to report abuse... Click to reply to this thread how to clear the DOS screen through java program 878207 Posts: 3 Registered: 08/09/11 Re: how to clear the DOS screen through java program Posted: 10-Aug-2011 01:42 in response to: 878207 in response to: 878207 Click to report abuse... System.out.println("\n") 50 times Ram Posts: 374 Registered: 09/18/10 Re: how to clear the DOS screen through java program Posted: 10-Aug-2011 03:54 in response to: 878207 in response to: 878207 Click to report abuse... 878207 wrote: System.out.println("\n") 50 times Very funny :D BIJ001 Posts: 62 Registered: 04/29/11 Re: how to clear the DOS screen through java program Click to reply to this thread Reply Click to reply to this thread Reply

Reply

Posted: 10-Aug-2011 04:00

in response to: 878207 in response to: 878207 Reply

Click to report abuse... Click to reply to this thread http://sourceforge.net/projects/javacurses/ gimbal2 Posts: 8,536 Registered: 08/20/10

Re: how to clear the DOS screen through java program Posted: 10-Aug-2011 04:48 in response to: BIJ001 in response to: BIJ001 Click to report abuse... Click to reply to this thread BIJ001 wrote: http://sourceforge.net/projects/javacurses/ Reply

Neat solution actually. In stead of relying on the OS command prompt, create you r own over which you do have full control. I think I remember someone posting a quick example on how to do that using Swing in the old Sun forum days. Of course more likely the OP is learning Java and is expecting too much from the command line features. Data Fiddler Posts: 4 Registered: 08/27/10 Re: how to clear the DOS screen through java program Posted: 11-Aug-2011 08:22 in response to: gimbal2 in response to: gimbal2 Click to report abuse... Click to reply to this thread Or start a new cmd process running java yourmain again. ( Why do you want a fresh console ? ) Reply

Yes, the good old days of DOS boxes supporting "ANSI" VT-100 escape sequences ar e gone. But this is not Java specific. To mimic ANSI DOS Box behavior, JCurses seems fine. BIJ001 Posts: 62 Registered: 04/29/11 Re: how to clear the DOS screen through java program Posted: 12-Aug-2011 07:29 in response to: Data Fiddler in response to: Data Fi ddler Click to report abuse... Click to reply to this thread Reply // just kidding tput clear baftos Posts: 3,431 Registered: 08/26/10 Re: how to clear the DOS screen through java program Posted: 12-Aug-2011 12:11 in response to: Data Fiddler in response to: Data Fi ddler

Click to report abuse... Click to reply to this thread Reply Just some Friday fun. Use the telnet program that comes with Windows and support s 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); } } jschell Posts: 41,925 Registered: 08/16/10 Re: how to clear the DOS screen through java program Posted: 12-Aug-2011 15:27 in response to: 878207 in response to: 878207 Click to report abuse... 878207 wrote: System.out.println("\n") 50 times Click to reply to this thread Reply

Perfectly reasonable and simple solution. This came up several years ago and someone noted at the time that with window bu ffering that might not be enough. But it might be sufficient in terms of the goal of the application.

Of course this is only reasonable if that is all you really want to do. If you a re trying to simulate a GUI screen in a console then one of the other suggestion s would be better. Pages: 1 Back to Thread List Back to Thread List Legend Guru Guru : 2500 - 1000000 pts Expert Expert : 1000 - 2499 pts Pro Pro : 500 - 999 pts Journeyman Journeyman : 200 - 499 pts Newbie Newbie : 0 - 199 pts Oracle ACE Director Oracle ACE Member Oracle Employee ACE Java Champion Helpful Answer (5 pts) Correct Answer (10 pts) Point your RSS reader here for a feed of the latest messages in all forums

Hardware and Software Engineered to Work Together About Oracle Oracle and Sun Oracle RSS Feeds Subscribe Careers Us Site Maps Legal Notices Terms of Use Your Privacy Rights

Contact

You might also like