Reputation: 1
Suppose If we create a bat file to run java program which prints "Hello World"
, like this
javac MyProgram.java
java MyProgram
After when I Double click that bat file It opens Command prompt and displays "Hello World"
result and automatically closes. Is there any solution to not to close Command prompt until and unless I type Exit in it.
Thanks.
Upvotes: 1
Views: 688
Reputation: 585
If you want to make the window remain for a while, there are 3 ways:
javac MyProgram.java java MyProgram
in a Command Prompt
window (fire up a new one, navigate to your working directory, execute it)Scanner a; ... ; a.nextLine()
) at the end of your program, you can then enter something or simply press a to make the program complete.try { Thread.Sleep(1000); } catch (Exception e) {}
Upvotes: 1
Reputation: 3181
It happens because at the end of the day it is a program. And it terminates once it is done with its execution..in your case, printing stuff.
You can manually open a command prompt and then drag and drop the .bat file onto this command prompt and run it. This way, you would still have the window open.
Upvotes: 0