是否可以在批处理文件中发出等待命令?

发布于 2024-10-26 08:43:36 字数 70 浏览 2 评论 0原文

我有一个运行多个 .cmd 文件的批处理文件。我想知道是否可以让它在运行最后一个之前等待 60 秒左右。

谢谢

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 before running the last one.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

木森分化 2024-11-02 08:43:36

您可以使用超时[秒],即超时60

you can use timeout [seconds] i.e. timeout 60

一紙繁鸢 2024-11-02 08:43:36

另一个“解决方法”是使用在各种 windows/dos OS-es 上得到更好支持的 choice 命令:

choice /c a /t 10 /d a > nul

将导致 10 秒的暂停,同时屏幕上看不到任何内容。

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.

樱桃奶球 2024-11-02 08:43:36

使用“睡眠”命令。您需要下载它(Windows资源包的一部分)
有关睡眠的更多信息

use the "Sleep" command. You need to download it (part of the Windows resource kits)
More information here on sleep

甜是你 2024-11-02 08:43:36

PING 127.0.0.1 -n 61

这个的作用是 ping 计算机本身,它总是会立即回复,并且 ping 之间的时间是 1 秒,第一个 ping 是立即的,所以只需添加多少您想要的秒数 + 1 作为要发送的 ping 数量。在这种情况下,它将等待 60 秒。

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.

挽清梦 2024-11-02 08:43:36

您可以使用 超时

Syntax
  TIMEOUT [seconds]

Windows Server 2003 资源工具包工具

Syntax
  SLEEP [seconds]

You can use Timeout

Syntax
  TIMEOUT [seconds]

or Sleep from the Windows Server 2003 Resource Kit Tools

Syntax
  SLEEP [seconds]
庆幸我还是我 2024-11-02 08:43:36

如果您更喜欢纯 cmd 脚本,请使用以下代码段。

首先,此代码片段返回当前时间(以百分之几秒为单位)。

: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 SETHELP CALL 信息。

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.

我也只是我 2024-11-02 08:43:36

快速谷歌搜索得出了这个答案...

PING 1.1.1.1 -n 1 -w 30000 >NUL

它会尝试 ping 直到超时(30000ms)

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)

随遇而安 2024-11-02 08:43:36

伟大的!所以这最终是正确的解决方案。
只是一个细节,如果您在本地化操作系统上使用它,请确保您的“DELIMS”设置适合。
例如,使用“DELIMS=:,”而不是“DELIMS=:”。用于捷克语本地化。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文