I am creating a simple batch file to assist in a few things, and I have some instructions that it prints out as well that I want the user to see before exit. Currently, the window closes very quickly. So I added PAUSE
at the end of the file, but it does not want to work.
I looked at other questions on SO and have checked to make sure the line endings are CRLF
and that I have CRLF
at the end of the file.
Any suggestions?
The most obvious way to pause a batch file is of course the PAUSE command. This will stop execution of the batch file until someone presses "any key". Well, almost any key: Ctrl, Shift, NumLock etc.
Ctrl+C. One of the most universal methods of aborting a batch file, command, or another program while it's running is to press and hold Ctrl + C .
A. Just add |more to the end of the command, e.g. would display the help one screen at a time.
TIMEOUT — Type timeout time where "time" is replaced by the number of seconds to delay. For example, typing in timeout 30 will delay your batch file for 30 seconds. If you want to prevent people from skipping the delay with a keypress, type in timeout time /nobreak (where "time" is the number of seconds to wait).
If the last command fails pause won't work.
You can fix it by putting "call" behind the command you are running (whatever command is before the pause) then the pause will work.
So for example I had a phpunit batch file that looked like this:
phpunit tests/sometests.php pause
When phpunit failed it just exited without pausing. Changing it to this made it pause correctly:
call phpunit tests/sometests.php pause
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With