2012-02-10 29 views
1

我想在批处理文件中添加时间延迟。批处理文件将在backgorund中静默运行。请帮帮我。批处理中的睡眠/等待命令

+0

和操作系统使用的是? – triclosan 2012-02-10 15:09:36

+0

Windows XP,Windows 7,Vista 64位和32位 – Ullan 2012-02-10 15:10:08

+0

如果没有更多信息,很难为您提供帮助。什么批语言?你试过什么了?什么系统?延迟多久?所有这些项目都是必要的,以提供良好的答案。 – Mei 2012-02-10 15:10:50

回答

3

你想使用超时。 超时10 将睡眠10秒

+0

如何静默使用超时.. cmmand命令提示符不应该显示 – Ullan 2012-02-10 15:12:59

+0

你应该看看使用实际编程语言来做到这一点。 请参阅http://stackoverflow.com/questions/166044/sleeping-in-a-batch-file for python,C++,perl等例子 – fiestacasey 2012-02-10 15:15:49

+3

@ HPFE455 - 简单地将输出重定向到nul:'> nul timeout 10' – dbenham 2012-02-10 18:13:57

3
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 
0

好的,烨使用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 

复制并粘贴在记事本上面的代码,并保存为 Anyname ** VBS ** 批处理文件的*“路径的例子。加上引号” *可能是: “C:\ ExampleFolder \ MyBatchFile.bat”

6

timeout 5

延迟

timeout 5 >nul

拖延不要求你按任意键取消