批量睡眠/等待命令

发布于 2025-01-04 13:43:56 字数 43 浏览 2 评论 0原文

我想在我的批处理文件中添加时间延迟。批处理文件将在后台静默运行。请帮我。

I want to add time delay in my batch file. The batch file will be running silently at backgorund. Please help me.

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

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

发布评论

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

评论(4

腹黑女流氓 2025-01-11 13:43:56

timeout 5

延迟

timeout 5 >nul

延迟而不要求您按任何键取消

timeout 5

to delay

timeout 5 >nul

to delay without asking you to press any key to cancel

时常饿 2025-01-11 13:43:56
ping localhost -n (your time) >nul

例子

@echo off
title Test
echo hi
ping localhost -n 3 >nul && :: will wait 3 seconds before going next command (it will not display)
echo bye! && :: still wont be any spaces (just below the hi command)
ping localhost -n 2 >nul && :: will wait 2 seconds before going to next command (it will not display)
@exit
ping localhost -n (your time) >nul

example

@echo off
title Test
echo hi
ping localhost -n 3 >nul && :: will wait 3 seconds before going next command (it will not display)
echo bye! && :: still wont be any spaces (just below the hi command)
ping localhost -n 2 >nul && :: will wait 2 seconds before going to next command (it will not display)
@exit
与风相奔跑 2025-01-11 13:43:56

你想使用超时。

timeout 10

会睡10秒

You want to use timeout.

timeout 10

will sleep 10 seconds

终止放荡 2025-01-11 13:43:56

好的,是的,您使用 timeout 命令来睡眠。但是要安静地完成整个过程,使用 cmd/batch 是不可能的。其中一种方法是创建一个VBScript,它将运行批处理文件而无需打开/显示任何窗口。
这是脚本:

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "PATH OF BATCH FILE WITH QUOTATION MARKS" & Chr(34), 0
Set WshShell = Nothing

将上面的代码复制并粘贴到记事本上并将其另存为
任意名称.**vbs

**
*“带有引号的批处理文件的路径”* 的示例可能是:
“C:\ExampleFolder\MyBatchFile.bat”

Ok, yup you use the timeout command to sleep. But to do the whole process silently, it's not possible with cmd/batch. One of the ways is to create a VBScript that will run the Batch File without opening/showing any window.
And here is the script:

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "PATH OF BATCH FILE WITH QUOTATION MARKS" & Chr(34), 0
Set WshShell = Nothing

Copy and paste the above code on notepad and save it as
Anyname.**vbs

**
An example of the *"PATH OF BATCH FILE WITH QUOTATION MARKS" * might be:
"C:\ExampleFolder\MyBatchFile.bat"

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