Windows Command Line (batch processing) file delay (sleep) Method

Source: Internet
Author: User
Tags sleep function

Windows Command Line (batch processing) file delay (sleep) Method

In Windows, the next batch processing file does not have the same Sleep function as in Linux for latency processing. Here there are two more practical methods to achieve latency:

1. Use the sleep function of WScirpt, with an accuracy of 0.001 seconds

Create a vbs delayed file, call it in the batch file, and use the sleep function of WScript to implement the sleep effect.

Practice:

1) Create the file sleep. vbs:

Echo WScript. sleep 5000> sleep. vbs

The content of sleep. vbs is as follows:

WScript. sleep 5000.

2) Create the sample file test. bat called in the batch processing file. The content is as follows:

SC stop OracleOraDb10g_home1TNSListener
Wscript sleep. vbs
SC start OracleOraDb10g_home1TNSListener

2. Use the ping timing function. The precision is 1 second.

Practice: Create the example file test2.bat with the following content:

SC stop OracleOraDb10g_home1TNSListener
Ping-n 3 127.0.0.1> nul
SC start OracleOraDb10g_home1TNSListener

Note: 3 is the number of sent ping packets, which can be used as the delay seconds. You need to set the delay seconds.

> Nul avoids screen output and sends the output to an empty device. Because no result is required, it only uses its timing function.

3. There are two ways to implement the Sleep function.

One is to exit the sleep function when the system time is continuously read and compared. However, this operation consumes a large amount of CPU, which is not recommended.

Another is a German Buddy's practice. A Timer Program is directly generated using the debug method, which may damage the system stability or be prone to virus implantation (using others' code ), it is not recommended.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.