14,974
edits
m (→MS-DOS) |
(→MS-DOS) |
||
| Line 2: | Line 2: | ||
== MS-DOS == | == MS-DOS == | ||
=== Approach 1: %RANDOM% + ping local === | |||
[https://stackoverflow.com/questions/8258087/bat-random-timeout batch file - .bat random timeout - Stack Overflow] | [https://stackoverflow.com/questions/8258087/bat-random-timeout batch file - .bat random timeout - Stack Overflow] | ||
* {{kbd | key=<nowiki>%RANDOM%</nowiki>}} returns an integer between 0 and 32767. | * {{kbd | key=<nowiki>%RANDOM%</nowiki>}} returns an integer between 0 and 32767. | ||
| Line 8: | Line 9: | ||
* 5 is the minimum value you want. The original range of values you want '0 to 60' became '5 ~ 65'. | * 5 is the minimum value you want. The original range of values you want '0 to 60' became '5 ~ 65'. | ||
* ping local address<ref>[https://stackoverflow.com/questions/735285/how-to-wait-in-a-batch-script windows xp - How to wait in a batch script? - Stack Overflow]</ref> | * ping local address<ref>[https://stackoverflow.com/questions/735285/how-to-wait-in-a-batch-script windows xp - How to wait in a batch script? - Stack Overflow]</ref> | ||
BAT file: | |||
<pre> | <pre> | ||
REM print current date & time | REM print current date & time | ||
| Line 20: | Line 23: | ||
</pre> | </pre> | ||
=== Approach 2: sleep package of CygWin === | |||
Requirement: Install [https://cygwin.com/install.html Cygwin] on {{Win}} & install {{kbd | key=<nowiki>sleep</nowiki>}} package | |||
Verify the installation of {{kbd | key=<nowiki>sleep</nowiki>}} package<ref>[https://stackoverflow.com/questions/9260014/how-do-i-install-cygwin-components-from-the-command-line How do I install cygwin components from the command line? - Stack Overflow]</ref><ref>[http://polarhome.com/service/man/?qf=SLEEP&af=0&tf=2&of=Cygwin SLEEP man page on Cygwin]</ref> | |||
# Key-in {{kbd | key=<nowiki>cmd</nowiki>}} to open command prompt ([https://www.lifewire.com/how-to-open-command-prompt-2618089 How to Open Command Prompt (Windows 10, 8, 7, Vista, XP)]) | |||
# Key-in {{kbd | key=<nowiki>where sleep</nowiki>}} or {{kbd | key=<nowiki>dir C:\cygwin64\bin\sleep.exe</nowiki>}} if the installation path of CygWin is {{kbd | key=<nowiki>C:\cygwin64\</nowiki>}}. | |||
<pre> | |||
# successful condition | |||
C:\Users\user>dir C:\cygwin64\bin\sleep.exe | |||
C:\cygwin64\bin\sleep.exe | |||
# failed condition | |||
File Not Found | |||
</pre> | |||
BAT file: | |||
<pre> | |||
REM print current date & time | |||
ECHO %date% %time% | |||
REM sleep 5 ~ 65 seconds | |||
SET /a timeout=%RANDOM% * 60 / 32768 + 5 | |||
C:\cygwin64\bin\sleep.exe %timeout% | |||
REM print current date & time | |||
ECHO %date% %time% | |||
</pre> | |||
=== Approach 3: TIMEOUT === | |||
Alternative command: {{exclaim}} The following command {{kbd | key=<nowiki>ECHO %date% %time%</nowiki>}} will not be executed after {{kbd | key=<nowiki>TIMEOUT %timeout%</nowiki>}} was executed. | Alternative command: {{exclaim}} The following command {{kbd | key=<nowiki>ECHO %date% %time%</nowiki>}} will not be executed after {{kbd | key=<nowiki>TIMEOUT %timeout%</nowiki>}} was executed. | ||
BAT file: | |||
<pre> | <pre> | ||
SET /a timeout=%RANDOM% * 60 / 32768 + 5 | SET /a timeout=%RANDOM% * 60 / 32768 + 5 | ||