• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Closing the DOS window?

 
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic