wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes keep cmd window open after System.exit(0) (.bat file) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "keep cmd window open after System.exit(0) (.bat file)" Watch "keep cmd window open after System.exit(0) (.bat file)" New topic
Author

keep cmd window open after System.exit(0) (.bat file)

Jorg Klein
Ranch Hand

Joined: Feb 13, 2006
Posts: 33
Hello,

I made a program and I run it with a .bat file.
This works fine but if my program crashes and it does a System.exit(0) the cmd screen closes at once.
I can't read the exception message thats printed on the cmd.
How can I make sure the cmd stays open?

I already tried running with java instead of javaw, that doenst solve the problem.

Regards,

Jorg Klein
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3460
    
  12
Open a command window and then run the .bat file from there.


Joanne
Jorg Klein
Ranch Hand

Joined: Feb 13, 2006
Posts: 33
Originally posted by Joanne Neal:
Open a command window and then run the .bat file from there.


I also already tried that but the .bat file was not visible from the command window for some strange reason.
If I looked in the dir with dir/p or dir I did not see my .bat file, very strange
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18752
    
  40

Originally posted by Jorg Klein:

I also already tried that but the .bat file was not visible from the command window for some strange reason.
If I looked in the dir with dir/p or dir I did not see my .bat file, very strange


That is incredibly strange... Maybe you were in the wrong location.


Anyway, another option is to have your batch file start yet another command window -- one that will stay around. In your batch file, do something like...

cmd /k java ...

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Jorg Klein
Ranch Hand

Joined: Feb 13, 2006
Posts: 33
finally, that works Henry!

start "ApplicationName" cmd /k "%JAVA_HOME%/bin/java" -cp .....

that works!!
thanks a lot!
I searched a long time for a solution!
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
You can use the "pause" command to block a bat file and optionally display a message like "Hit any key to continue, any other key to quit."

Hmmm, just tried it an it doesn't take an optional message. Maybe that was OS/2.
[ March 03, 2006: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
 
subject: keep cmd window open after System.exit(0) (.bat file)