aspose file tools*
The moose likes Beginning Java and the fly likes Closing the DOS window? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Closing the DOS window?" Watch "Closing the DOS window?" New topic
Author

Closing the DOS window?

Sam Bluesman
Ranch Hand

Joined: Nov 21, 2004
Posts: 191
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


Moosey knows best
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

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.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
kwame Iwegbue
Ranch Hand

Joined: Sep 02, 2000
Posts: 197
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 ]

Who dares, wins! (SAS motto)
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
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.


Tony Morris
Java Q&A (FAQ, Trivia)
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14111
    
  16

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Closing the DOS window?