Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch file command PAUSE does not work

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?

like image 486
Samaursa Avatar asked Jan 12 '11 06:01

Samaursa


People also ask

How do I put a pause in a batch file?

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.

How do you stop a batch file from running?

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 .

How do I pause command line output?

A. Just add |more to the end of the command, e.g. would display the help one screen at a time.

How do I pause a few seconds in a batch file?

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).


1 Answers

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 
like image 141
Tim Avatar answered Sep 18 '22 22:09

Tim