我有一个批处理文件,它运行多个 .cmd 文件。 我想知道是否可以在运行最后一个文件之前等待60秒左右。
谢谢
我有一个批处理文件,它运行多个 .cmd 文件。 我想知道是否可以在运行最后一个文件之前等待60秒左右。
谢谢
timeout [秒数]
,例如timeout 60
。该命令用于设置超时时间。choice
命令,该命令在各种Windows/Dos操作系统上得到更好的支持。choice /c a /t 10 /d a > nul
将导致暂停10秒钟,屏幕上将不会显示任何内容。
PING 127.0.0.1 -n 61
这个命令是ping本机,它会立即回复,每次ping的时间间隔为1秒,第一次ping会立即发送,所以只需将想要等待的秒数加上1作为要发送的ping次数即可。在这种情况下,它将等待60秒。
: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
然后,您可以使用它来构建如下的等待循环。
:wait
call :gettime wait0
:w2
call :gettime wait1
set /A waitt = wait1-wait0
if !waitt! lss %1 goto :w2
goto :eof
@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
关于这里使用的命令的更详细描述,请查看HELP SET
和HELP CALL
信息。