Editing
Sleep in Mandarin
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Windows 下的 MS-DOS == === 方法 1:使用 %RANDOM% 加上 ping 本地 === 目的 * 在 5 到 60 秒之間隨機暫停 批處理檔案: <pre> REM 列印當前日期與時間 ECHO %date% %time% REM 暫停 5 到 60 秒 SET /a timeout=%RANDOM% * 55 / 32767 + 5 ping 127.0.0.1 -n %timeout% > nul REM 列印當前日期與時間 ECHO %date% %time% </pre> 說明<ref>[https://stackoverflow.com/questions/8258087/bat-random-timeout 批處理檔案 - .bat 隨機暫停時間 - Stack Overflow]</ref> * {{kbd | key=<nowiki>%RANDOM%</nowiki>}} 會返回一個介於 0 和 32767 之間的整數<ref>[https://ss64.com/nt/syntax-random.html 隨機數字 - Windows 命令 - SS64.com]</ref>。 * 55 是你想要的範圍:5 到 60。 * 32767 是由 {{kbd | key=<nowiki>%RANDOM%</nowiki>}} 返回的數值範圍(0 到 32767)。 * 5 是你想要的最小值。原始數值範圍是「0 到 55」。加上 5 之後範圍變成了「5 到 60」。 * ping 本地地址:{{kbd | key=<nowiki>/n <Count></nowiki>}} "指定發送的回聲請求消息數量。預設值是 4。"<ref>[https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/ping 時間]</ref><ref>[https://stackoverflow.com/questions/735285/how-to-wait-in-a-batch-script windows xp - 如何在批處理腳本中等待? - Stack Overflow]</ref> === 方法 2:使用 CygWin 的 sleep 套件 === 要求:在 {{Win}} 上安裝 [https://cygwin.com/install.html Cygwin] 並安裝 {{kbd | key=<nowiki>sleep</nowiki>}} 套件(如何安裝:[https://x.cygwin.com/docs/ug/setup.html 設定 Cygwin/X]) 驗證 {{kbd | key=<nowiki>sleep</nowiki>}} 套件的安裝<ref>[https://stackoverflow.com/questions/9260014/how-do-i-install-cygwin-components-from-the-command-line 如何從命令行安裝 cygwin 組件? - Stack Overflow]</ref><ref>[http://polarhome.com/service/man/?qf=SLEEP&af=0&tf=2&of=Cygwin SLEEP 手冊頁面在 Cygwin 上]</ref> 1. 輸入 {{kbd | key=<nowiki>cmd</nowiki>}} 打開命令提示符([https://www.lifewire.com/how-to-open-command-prompt-2618089 如何打開命令提示符(Windows 10、8、7、Vista、XP)]) 2. 輸入以下其中一個命令 * 如果你將 CygWin 的安裝路徑添加到系統路徑,輸入 {{kbd | key=<nowiki>where sleep</nowiki>}}([[How to setup my system path | 如何設置我的系統路徑]])。或 * 如果 CygWin 的安裝路徑是 {{kbd | key=<nowiki>C:\cygwin64\</nowiki>}},輸入 {{kbd | key=<nowiki>dir C:\cygwin64\bin\sleep.exe</nowiki>}}。 <pre> C:\Users\user>dir C:\cygwin64\bin\sleep.exe # 成功條件 C:\cygwin64\bin\sleep.exe # 失敗條件 檔案未找到 </pre> 批處理 檔案: <pre> REM 列印當前日期與時間 ECHO %date% %time% REM 暫停 5 到 60 秒 SET /a timeout=%RANDOM% * 55 / 32767 + 5 C:\cygwin64\bin\sleep.exe %timeout% REM 列印當前日期與時間 ECHO %date% %time% </pre> === 方法 3:TIMEOUT === 替代命令:{{exclaim}} 在執行了 {{kbd | key=<nowiki>TIMEOUT %timeout%</nowiki>}} 之後,以下命令 {{kbd | key=<nowiki>ECHO %date% %time%</nowiki>}} 將不會被執行。 批處理檔案: <pre> SET /a timeout=%RANDOM% * 55 / 32767 + 5 TIMEOUT %timeout% ECHO %date% %time% </pre>
Summary:
Please note that all contributions to LemonWiki共筆 are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
LemonWiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Current events
Recent changes
Random page
Help
Categories
Tools
What links here
Related changes
Special pages
Page information