Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sleep/Wait command in Batch [duplicate]

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

like image 206
Ullan Avatar asked Feb 10 '12 15:02

Ullan


People also ask

How do you wait 1 second in a batch file?

Type in your command. TIMEOUT — Type timeout time where "time" is replaced by the number of seconds to delay. For example, typing in timeout 30 will delay your batch file for 30 seconds.

Is there a wait command in batch?

The Sleep/Wait Command is a very useful command that is used to pause for a set amount of time while a batch script is being executed. To put it another way, this command makes it easier to run a command for a set amount of time.

How do you pause 10 seconds in a batch file?

You can insert the pause command before a section of the batch file that you might not want to process. When pause suspends processing of the batch program, you can press CTRL+C and then press Y to stop the batch program.

How do I change the sleep time in a batch file?

The correct way to sleep in a batch file is to use the timeout command, introduced in Windows 2000.


3 Answers

timeout 5

to delay

timeout 5 >nul

to delay without asking you to press any key to cancel

like image 156
The Moo Avatar answered Oct 02 '22 10:10

The Moo


You want to use timeout. timeout 10 will sleep 10 seconds

like image 31
fiestacasey Avatar answered Oct 02 '22 12:10

fiestacasey


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
like image 34
Itsproinc Avatar answered Oct 02 '22 10:10

Itsproinc