Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Closing the DOS window?

 
Sam Bluesman
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i am asking the user to enter data into a dos window, how do i program it so that if the user types something, such as "exit" the dos window will close?

Thanks
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think that you can -- at least not without using native code. And then, closing the window will terminate the processes it's running, so your Java program will end, too.

You're probably better off writing/finding/using a Java-console (a JFrame with a JTextArea that you can set listeners on, etc), not a DOS-console.
 
kwame Iwegbue
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i guess you can put an if statement in you code that tests the command line args to see if == "exit", then call something like System.exit(0)



you could also then write a line following this that calls a batch program which executes close command for DOS window. (can you write MS DOS scripts?)
[ November 15, 2005: Message edited by: kwame Iwegbue ]
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As fas as Java is concerned, there is no DOS window. Too often, I see the obscuring of the Java platform alongside some other platform. It is important to acknowledge that you're using the Java platform, not DOS, not Windows, not Linux, not anything, but Java.

If you look at your code, you'll see that you're conforming to an API Specification. For example, you're reading data in from the standard input stream and probably writing data out to the standard output stream. That this data appears as a DOS window to you, at some given point in time, has nothing at all to do with the Java platform, since it knows only of the standard input stream and the standard output stream (or more accurately, what the API spec. says).

Unfortunately, there are some corner cases where Java "leaks" its abstraction to the underlying platform, but not for this case.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15483
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't want a command window to appear, start your program with "javaw" instead of "java", i.e. create a shortcut on your desktop and use "%JAVA_HOME%\bin\javaw.exe MyClassName" as the target to execute.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic