21

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

lospejos's user avatar
lospejos
1,9864 gold badges19 silver badges38 bronze badges
askedFeb 10, 2012 at 15:07
Ullan's user avatar
5
  • windows XP, windows 7, Vista both 64 and 32 bitCommentedFeb 10, 2012 at 15:10
  • It is hard to help you without more information. What batch language? What have you tried so far? What system? How long of a delay?All of these items are necessary to provide a good answer.CommentedFeb 10, 2012 at 15:10
  • Seewindows batch: sleep.CommentedFeb 10, 2012 at 15:11
  • Just I want to use a DOS commands to run a batch file at the backgorund. The OS I am going to use XP,Vista and Win7. Expecting dleay is amay be about 3-10 seconds. I tried the batch with out delay, but its not deleting a folder since that is used by another application. so I have to wait for few seconds for the exitCommentedFeb 10, 2012 at 15:15
  • The ping command popping up the command prompt.. the batch should run at back end.. can we hide the command prompt..CommentedFeb 10, 2012 at 15:16

4 Answers4

39

timeout 5

to delay

timeout 5 >nul

to delay without asking you to press any key to cancel

answeredOct 10, 2014 at 22:44
The Moo's user avatar
Sign up to request clarification or add additional context in comments.

2 Comments

Full sintax is available with TIMEOUT /?
There's a/nobreak option. Also note thattimeout cannot run in background.
5
ping localhost -n (your time) >nul

example

@echo offtitle Testecho hiping 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
answeredDec 22, 2012 at 17:44
Itsproinc's user avatar

Comments

5

You want to use timeout.

timeout 10

will sleep 10 seconds

Boken's user avatar
Boken
5,43810 gold badges41 silver badges47 bronze badges
answeredFeb 10, 2012 at 15:10
fiestacasey's user avatar

3 Comments

How to use timeout silently.. the cmmand prompt should not be displayed
you should probably look into using actual programming language to do this then. seestackoverflow.com/questions/166044/sleeping-in-a-batch-file for python, c++, perl, etc examples
@HPFE455 - simply redirect the output to nul:>nul timeout 10
0

Ok, yup you use thetimeout command to sleep. But to do the whole process silently, it's not possible with cmd/batch. One of the ways is to create aVBScript that will run theBatch 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), 0Set WshShell = Nothing

Copy and paste the above code on notepad and save it asAnyname.**vbs**An example of the *"PATH OF BATCH FILE WITH QUOTATION MARKS" * might be: "C:\ExampleFolder\MyBatchFile.bat"

answeredAug 10, 2014 at 17:08
Student Seng's user avatar

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.