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?
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
Does the last command before pause execute successfully? Mind sharing your script - at least last few commands?
Alternatively, since you seem to be using Windows7, try Timeout command and see if that is working.
I was having issues even on echo... assuming it was caused by long batch file... Pause was executing but it was not pausing, it was almost like that it was pressing a key after Pause was executed.
Tried suggested solutions above; none worked.
So just for future reference, here is what I did:
Basically just "pause > nul && pause > nul"; works every time.
@echo off
CALL :ForcePause "Press any key to resume."
ECHO.
ECHO Hello World!
ECHO.
CALL :ForcePause "Press any key to exit."
EXIT
REM You can remove echo if you don't want to pass custom string for pause
:ForcePause
echo %~1
pause > nul && pause > nul
GOTO :EOF
链接地址: http://www.djcxy.com/p/30342.html
上一篇: 如何在Windows的命令提示符下睡5秒钟? (或DOS)
下一篇: 批处理文件命令PAUSE不起作用