Close Menu
Computing.net
    Facebook X (Twitter) Instagram
    Computing.netComputing.net
    • News
      1. AI
      2. Crypto
      3. Gaming
      4. Hardware
      5. Security
      6. Software
      7. View All

      Anthropic’s COBOL Automation Tool Triggers IBM Stock Plunge and Crypto Market Decline

      February 24, 2026

      AI Trading Bot Loses $441K in Crypto After Decimal Point Mistake

      February 23, 2026

      Tesla (TSLA) Stock: Goodbye Sedans, Hello Robots in Dramatic Production Shift

      January 29, 2026

      Palantir Technologies (PLTR) Stock: Why Bears May Be Wrong About Valuation Concerns

      January 29, 2026

      SUI Token Rallies 40% Following Major Staking Event and CME Futures Announcement

      May 12, 2026

      Chainlink (LINK) Surges to $10.40 as Network Activity Hits Eight-Month Peak

      May 12, 2026

      Dogecoin Whales Ramp Up Accumulation as DOGE Eyes Critical Breakout Levels

      May 12, 2026

      Bitcoin Holds $81K While Burry Flags Nasdaq Bubble and Oil Surges Past $105

      May 12, 2026

      Hamster Kombat: Unraveling TON’s Gaming Phenomenon

      August 7, 2024

      W-Coin: Exploring the Latest Telegram Tap-to-Earn Phenomenon

      August 7, 2024

      Hamster Kombat: 300 Million Players & Counting, HMSTR Token Airdrop Soon!

      July 31, 2024

      Hamster Kombat Developers Work with TON Team on Airdrop Solution

      July 30, 2024

      Nothing Expands Product Line with New AI Feature & Phone Update

      July 31, 2024

      Security Audit Reveals Concerns in Atari’s Blockchain Game on Base

      August 6, 2024

      SideWinder Group Targets Maritime Facilities in New Cyber Espionage Campaign

      July 30, 2024

      OAuth Implementation Flaw Exposes Millions of Websites to XSS Attacks

      July 30, 2024

      Hamster Kombat Players Face Growing Cybersecurity Threats

      July 25, 2024

      Anthropic’s COBOL Automation Tool Triggers IBM Stock Plunge and Crypto Market Decline

      February 24, 2026

      Cookie Crumble: Google Halts Plans to Eliminate Third-Party Cookies in Chrome

      July 23, 2024

      Big Brother is Watching: Apple’s Creepy New Ad Urges iPhone Users to Ditch Chrome

      July 23, 2024

      Nvidia Stock Soars to New Record at $219.44 Ahead of May 20 Earnings

      May 12, 2026

      Rocket Lab Shares Surge Past $120 Following Wave of Analyst Upgrades

      May 12, 2026

      GM Shares Decline Following 600 IT Layoffs Amid Strategic AI Workforce Transformation

      May 12, 2026

      SES Delivers €847M Q1 Performance as Intelsat Integration and Aviation Deals Fuel Expansion

      May 12, 2026
    • How To

      Batch Files: Tokens and Delimiters (FOR Loops)

      July 31, 2024

      Types of Ethernet Cabling & Electrical Low Voltage Wiring

      July 9, 2024

      What You Should Know About .JSON File Extension

      January 10, 2023

      Bkup File Extension

      November 19, 2022

      HEIC File Extension

      November 19, 2022
    • Office
      1. Excel
      2. Google Sheets
      3. View All

      How to Convert Column List to Comma Separated List in Excel

      July 24, 2024

      How to Find the Last Monday of the Month in Excel

      July 24, 2024

      Convert Bytes to MB or GB in Excel: 3 Methods!

      July 24, 2024

      How to Remove Characters from Right in Excel

      July 30, 2023

      How to Subtract in Google Sheets: Complete Guide

      July 31, 2024

      Bullet Points in Google Sheets

      January 20, 2022

      Sort by Date in Google Sheets

      January 18, 2022

      Google Sheets Timestamp

      January 17, 2022

      How to Subtract in Google Sheets: Complete Guide

      July 31, 2024

      How to Convert Column List to Comma Separated List in Excel

      July 24, 2024

      How to Find the Last Monday of the Month in Excel

      July 24, 2024

      Convert Bytes to MB or GB in Excel: 3 Methods!

      July 24, 2024
    • Answers
    • About
    • Contact
    Facebook X (Twitter)
    Computing.net
    How To

    How to Put Delay / Sleep in Batch Files

    Computing StaffBy Computing StaffOctober 5, 2021
    Twitter LinkedIn Email Telegram
    Twitter LinkedIn Email Telegram

    Hi Guys,

    Today I’m gonna post something on doing some delay /wait time in batch files.We have seen many people’s asking help as to how they can  put some sleep time between commands within a batch file.  Unfortunately there is no such built in commands available to accomplish this in windows ,however using some workarounds we can do. Usually when I started with batch files I though there is no such thing to do at least from command prompt, later I came to know few ways.

    First of all, If you want the delay just  to allow some other program to finish then the best thing to use Start /w option.

    i) Start /w

    START /W program.exe

    program.exe means the program executable you want to execute. The batch file will wait until the program terminates. The advantage is it won’t use any extra CPU/Memory while waiting.

    ii) Using Ping command 

    There are 2 ways to use ping (may be others as well which i am not aware)

    Ping -n and ping -w

    The ping –n parameter pings the given ip for n number of time. We assume it takes one second to ping once. But that is not the case always. If exact timing is not required then we can use this option. The idea is to ping your computer itself (localhost ,IP 127.0.0.1) n number of times. So its , Ping –n 30 127.0.0.1 it will wait for 30 secs approx before going to next line of code. But it will produce the ping output to the console. To hide this use the redirector to redirect the output to null device.

    Ping –n 30 127.0.0.1 >null

    The disadvantage using this method is ping response depends on various bits, like the network card performance, computer speed, available memory so -30 does not means it will use exact 30 secs. On a modern faster computer it can take about 20 secs or on a old PIII computer it can take more than 30.

    So, lets try another work around. The ping command comes with a parameter –w .

    Ping –w 6000 128.0.0.1

    -w parameter tells ping to wait until specified time(In millisecond)  before it says request timeout or not reachable.The idea is to ping an non-exist IP and tell it to wait for the time we want. Like in above example I m pinging 128.0.0.1 which does not exist as per my understating (Check yourself before implening and If it replies use another IP). I asked it to wait for 6000 milisecs (6 Secs) and it does wait exactly for 6 seconds. So its even better than the –n option, make sure to use the redirector to redirect output to nul.

    iii) The choice command.

    Windows vista and letter comes with a command Choice. CHOICE has the “/t” option which lets it automatically select an option for you after a time delay. Actually This tool allows users to select one item from a list of choices and returns the index of the selected choice. The number of seconds to pause before a default  choice is made. Acceptable values are from 0 to  9999. If 0 is specified, there will be no pause  and the default choice is selected. Try this:

    choice /t 3  /d Y >null

    The command prompt will wait for 3 seconds before it comes next.

    /t switch tells it to wait till specified seconds and /d tells it to chose Y as a default choice , We don’t have to do anything with the default choice here. Choice can be used as an alternative to the set /p command in case you want a menu to be presented to console to choose an option. Choice has the limitation that it is not available in windows xp/2003 and it will terminate if you press any key while it is running.

    Alright.. We have seen 3 methods above, the little problem with them is that they use lot of CPU time while execution. Lets see a way in which we can keep waiting without loosing CPU time/power/resourses and my fav one.

    iv) Using vbscript to do the sleep

    Windows Scripting host (WSH) sleep will use very less CPU and can be used for long delays as well.  It’s a built in feature and the VBS file can be created over the file from the existing batch file in simple to understand code. Let’s see how we can accomplish this. I m putting explanation in braces.

    @echo off (Our normal batch code)
    echo Wscript.Sleep 10000> %temp%\sleep.vbs   (add this line below echo off or anywhere before you want sleep)
    start /w wscript.exe %temp%\sleep.vbs (put this line where you want sleep)
    del %temp%\sleep.vbs   (Put this in the end to cleanup J )

    Isn’t that simple enough. Note that the value 10000 is in millisecond. It accepts milliseconds value. This will not work if you don’t have write access to target (Temp) directory ,it happned in rare case where your user wont have access to the temp folder itself.

    So..thats all for today>hope you enjoyed.

    Share. Twitter LinkedIn Email Telegram
    Avatar photo
    Computing Staff
    • Website

    Related Posts

    Batch Files: Tokens and Delimiters (FOR Loops)

    July 31, 2024

    Types of Ethernet Cabling & Electrical Low Voltage Wiring

    July 9, 2024

    What You Should Know About .JSON File Extension

    January 10, 2023

    Bkup File Extension

    November 19, 2022

    HEIC File Extension

    November 19, 2022

    Working with Batch variables and For loops

    October 6, 2021
    Add A Comment

    Comments are closed.

    Latest

    Nvidia Stock Soars to New Record at $219.44 Ahead of May 20 Earnings

    May 12, 2026

    Rocket Lab Shares Surge Past $120 Following Wave of Analyst Upgrades

    May 12, 2026

    GM Shares Decline Following 600 IT Layoffs Amid Strategic AI Workforce Transformation

    May 12, 2026

    SES Delivers €847M Q1 Performance as Intelsat Integration and Aviation Deals Fuel Expansion

    May 12, 2026

    Trump Dismisses Iran Peace Proposal — Oil Markets React as Hormuz Remains Restricted

    May 12, 2026
    • Facebook
    • Twitter

    Latest Reviews

    Meta Platforms Shares Tumble 8% Despite Strong Q1 Performance Amid AI Investment Surge

    April 30, 2026

    Flush.com Review: Casino & Sportsbook With 275% Welcome Bonus

    March 7, 2026

    Katsubet Review: Crypto Casino With 300% Welcome Bonus & Free Spins

    March 7, 2026

    7Bit Review: Crypto Casino With 325% Bonus & 250 FS

    March 7, 2026

    Mega Dice Review: Crypto Casino With 200% Bonus & 50 Free Spins, Legit?

    March 7, 2026


    Home / Privacy Policy / Terms & Conditions

    Computing.net © 1996 - 2026 Kooc Media Ltd. All rights reserved. Registered Company No.05695741

    Type above and press Enter to search. Press Esc to cancel.