I have a bat file like this:
ipconfig
That will print out the ip info to the screen, but before the user can read that info CMD closes it's self.
I believe that CMD assumes the script has finished, so it closes.
How do I keep CMD open after the script is finished?
Thanks!
Depending on how you are running the command, you can put /k
after cmd
to keep the window open.
cmd /k my_script.bat
Put pause
at the end of your .BAT file.
just Add @pause
at the end
Example :
@echo off
ipconfig
@pause
or u can also use :
cmd /k ipconfig
Just to clarify something that took me a little bit to understand after reading these responses...
You have to type (literally) "cmd /k" followed by your command. I, at first, thought that "cmd" was to be replaced by your command. Not the case!
For instance I was trying to run java command...
cmd /k java myPackage.myClass
It kept the window open so I could see my "System.out.println()" messages.
I hope this clarification saves someone the approximately 3.5 minutes it took me to figure it out.
Adding pause
in (Windows 7) to the end did not work for me
but adding the cmd /k
in front of my command did work.
Example :
cmd /k gradlew cleanEclipse
start cmd /k
did the magic for me. I actually used it for preparing cordova phonegap app it runs the command, shows the result and waits for the user to close it. Below is the simple example
start cmd /k echo Hello, World!
What I did use in my case
start cmd /k cordova prepare
Update
You could even have a title for this by using
start "My Title" echo Hello, World!
If you are starting the script within the command line, then add exit /b
to keep CMD opened
javac -d C:\xxx\lib\ -classpath C:\xxx\lib\ *.java
cmd cd C:\xxx\yourbat.bat
the second command make your cmd window not be closed.
The important thing is you still able to input new command
In Windows add '& Pause' to the end of your command in the file.