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.
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) {}
try { Thread.Sleep(1000); } catch (Exception e) {}
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.