2012-02-10 80 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

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