Ways to Delay Batch Files

Author: John Stephens
Date Of Creation: 21 January 2021
Update Date: 1 July 2024
Anonim
Batch Ep.05 - Adding Delays
Video: Batch Ep.05 - Adding Delays

Content

This wikiHow teaches you how to prevent a batch file from automatically executing as soon as it is opened. There are a number of different commands you can use to defer a batch file according to your needs. Note that you should master how to write a batch file before attempting to defer this type of script file.

Steps

  1. . Click the Windows logo in the lower left corner of the screen.
    • If you have a batch file that needs delaying, just right-click on it and select Edit (Edit) to open the file in Notepad. In this case, you can skip the next two steps.

  2. Open Notepad. Import notepad to find the Notepad program, then click Notepad at the top of the Start window.
  3. Create batch file. Usually, you need to start with a command @echo off, then import the content of the batch file as you like.
  4. Determine how you want to defer the file. There are three main commands that you can use to defer batch files:
    • PAUSE Causes the batch file to pause until you press certain standard keys (such as spaces).
    • TIMEOUT The batch file will wait for the specified number of seconds (or keypress) before continuing.
    • PING Pause the batch file until the file receives the ping command from the specified computer address. This usually causes a short delay when you ping the execution address.

  5. Select the file delay location. You can defer the batch file anywhere in the code (save it after the "Exit" command if you have used the previous command). Scroll down until you find the point where you want to defer the file, then make a space between the code before and after the delay point.
  6. Enter an order. Depending on your needs, enter one of the following commands:
    • PAUSE - Type pause on the command line. You don't need to add any content.
    • TIMEOUT - Type timeout time, in which "time" is replaced with the number of seconds you want to delay. For example, if you want to delay the batch file for 30 seconds, type timeout 30.
      • If you want to prevent others from skipping pauses with a certain keypress, type timeout time / nobreak (where "time" is the number of seconds to delay).
    • PING - Type ping address, where "address" is the IP address of the computer or website you want to PING.

  7. Save the document as a batch file. If you haven't saved the document as a batch file, please:
    • Click File (File), select Save As ... (Save as).
    • Enter the filename, followed by the extension .bat (for example, "My Batch File" would be "My Batch File.bat").
    • Click the "Save as type" drop-down box then select All Files (All files).
    • Select a save location, then click Save (Save).
    advertisement

Advice

  • You can execute the batch file on any Windows computer by double-clicking the file.
  • The "PAUSE" command is best suited when you rely on a certain user to trigger the next batch file, while the "TIMEOUT" command is suitable if you want to allow the file to execute automatically.

Warning

  • The previous "SLEEP" command no longer works on Windows 10.
  • Batch files will not run on Mac computers.