Windows command Line (batch) file delay (sleep) method

Source: Internet
Author: User
Tags sleep function

There are 2 more practical ways to delay processing a batch file in Windows without delaying the sleep function like Linux:

1, using the sleep function of wscirpt, precision 0.001 seconds

Create a VBS delay file, and then call it in a batch file, using the WScript sleep function to achieve the effect of sleep.

Actual combat:

1) Create file Sleep.vbs:

echo Wscript.Sleep > Sleep.vbs

Sleep.vbs content is as follows:

Wscript.Sleep 5000.

2) Called in the batch file, create the sample file Test.bat, as follows:

sc stop Oracleoradb10g_home1tnslistener
Wscript Sleep.vbs
SC start Oracleoradb10g_home1tnslistener


2, the use of ping timing function, the accuracy of 1 seconds

Actual combat: Create the sample file Test2.bat, as follows:

sc stop Oracleoradb10g_home1tnslistener
Ping-n 3 127.0.0.1>nul
SC start Oracleoradb10g_home1tnslistener

Description: 3 is the number of ping packets sent, which can be used as a delay of seconds, which requires a few seconds to be set.

The >nul avoids screen output and inputs the output to an empty device because no results are required and only its timing function is used.


3, there are two ways to achieve sleep function

One is through the continuous reading system time, to achieve a certain value when the exit to realize the sleep function, but the operation should be CPU large, not recommended.

The other is a German friend of the practice, directly using the Debug method to generate a timer program, the method may damage the stability of the system, or easily implanted virus (using other people's code), nor recommended.

Windows command Line (batch) file delay (sleep) method

Related Article

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.