How do I make a batch file wait / sleep for some seconds?



As an IT administrator, it is important to understand the basics of creating and working with batch files. A batch file is a script that can be used to automate tasks, such as running programs, or performing system maintenance. In some cases, it may be necessary to add a delay in the execution of a batch file. This can be accomplished by adding a “wait” or “sleep” command to the batch file.

The most common way of adding a delay to a batch file is to use the Windows “timeout” command. The timeout command has the following syntax:

timeout /t

where is the number of seconds to wait before continuing. For example, to wait for 10 seconds before continuing, the command would be:

timeout /t 10

You can also specify the number of minutes to wait, by using the following syntax:

timeout /t

where is the number of minutes to wait before continuing. For example, to wait for 5 minutes before continuing, the command would be:

timeout /t 5

The timeout command can also be used to wait for a specific time of day. This is done by using the following syntax:

timeout /t HH:MM

where HH is the hour and MM is the minutes. For example, to wait until 3:00 PM, the command would be:

timeout /t 15:00

The timeout command can also be used to wait until a specific number of seconds has passed since the start of the batch file. This is done by using the following syntax:

timeout /t %TIMEOUT%

where %TIMEOUT% is the number of seconds to wait before continuing. For example, to wait for 60 seconds before continuing, the command would be:

timeout /t %TIMEOUT%

There are other ways to add a delay to a batch file. For example, you can use the “sleep” command, which has the following syntax:

sleep

where is the number of seconds to wait before continuing. For example, to wait for 10 seconds before continuing, the command would be:

sleep 10

You can also use the “ping” command to add a delay to a batch file. This is done by using the following syntax:

ping -n 127.0.0.1 > nul

where is the number of seconds to wait before continuing. For example, to wait for 10 seconds before continuing, the command would be:

ping -n 10 127.0.0.1 > nul

The “ping” command can also be used to wait for a specific number of seconds since the start of the batch file. This is done by using the following syntax:

ping -n %TIMEOUT% 127.0.0.1 > nul

where %TIMEOUT% is the number of seconds to wait before continuing. For example, to wait for 60 seconds before continuing, the command would be:

ping -n %TIMEOUT% 127.0.0.1 > nul

In addition to the methods mentioned above, there are other ways to add a delay to a batch file. For example, you can use the “choice” command, which has the following syntax:

choice /t /d y /n

where is the number of seconds to wait before continuing. For example, to wait for 10 seconds before continuing, the command would be:

choice /t 10 /d y /n

The “choice” command will also display a “Yes or No” prompt, which can be used to prompt the user for input. The “choice” command can be used to display a message and wait for user input, by using the following syntax:

choice /t /d y /m

where is the number of seconds to wait before continuing and is the message to be displayed. For example, to wait for 10 seconds and display a message, the command would be:

choice /t 10 /d y /m “Please wait 10 seconds”

These are just some of the ways to add a delay to a batch file. By understanding the different methods available, an IT administrator can easily add a delay to a batch file. This can be a useful way to automate tasks, such as running programs, or performing system maintenance.

Inquire Now

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Find your next full or part-time role here

ScaleDesk can either help you find your next full time gig or a part time side gig where you can create extra income!

Onboard with us once
Skip HR screening and go to the final interview with with only your resume and a video interview you never have to redo
Get paid electronically every month for the hours you work
We will be your reference even if you work for us once

IT Teams: Use ScaleDesk to augment your team

Schedule Demo