Is it possible to issue a wait command in a batch file?
I have a batch file that runs several .cmd files. I would like to know if it is possible to have it wait 60 seconds or so bef开发者_如何学编程ore running the last one.
Thanks
you can use timeout [seconds]
i.e. timeout 60
Another "workaround" is by using the choice
command which is better supported on the various windows/dos OS-es:
choice /c a /t 10 /d a > nul
will cause a pause of 10 seconds while nothing will be seen on the screen.
use the "Sleep" command. You need to download it (part of the Windows resource kits) More information here on sleep
PING 127.0.0.1 -n 61
What this does is ping the computer itself, it will always reply instantly, and the time between pings is 1 second, and the first ping goes instantly, so just add how many seconds you want + 1 as the number of pings to send. In this case, it will wait 60 seconds.
You can use Timeout
Syntax
TIMEOUT [seconds]
or Sleep from the Windows Server 2003 Resource Kit Tools
Syntax
SLEEP [seconds]
If you prefer a pure cmd script, use the following pieces of code.
First, this snippet returns the current time in hundreths of seconds.
:gettime
set hh=%time:~0,2%
set mm=%time:~3,2%
set ss=%time:~6,2%
set cc=%time:~-2%
set /A %1=hh*360000+mm*6000+ss*100+cc
goto :eof
You may then use it to build a wait loop like this.
:wait
call :gettime wait0
:w2
call :gettime wait1
set /A waitt = wait1-wait0
if !waitt! lss %1 goto :w2
goto :eof
and, finally, putting all pieces together, you have this example of usage
@echo off
setlocal enableextensions enabledelayedexpansion
call :gettime t1
echo %t1%
call :wait %1
call :gettime t2
echo %t2%
set /A tt = (t2-t1)/100
echo %tt%
goto :eof
:wait
call :gettime wait0
:w2
call :gettime wait1
set /A waitt = wait1-wait0
if !waitt! lss %1 goto :w2
goto :eof
:gettime
set hh=%time:~0,2%
set mm=%time:~3,2%
set ss=%time:~6,2%
set cc=%time:~-2%
set /A %1=hh*360000+mm*6000+ss*100+cc
goto :eof
For a more detailed description of the commands used here, check HELP SET
and HELP CALL
information.
A quick google search came up with this answer...
PING 1.1.1.1 -n 1 -w 30000 >NUL
It'll try and ping until the timeout (30000ms)
GREAT! So THIS one is the correct solution, finnaly. Just a detail, if You use it at the localised OS, make sure Your "DELIMS" setting fits. For example, use "DELIMS=:," instead of "DELIMS=:." for Czech localisation.
精彩评论