Windows バッチで X 秒スリープまたは待機する方法

timeout
(> Windows 7/2008)
timetout
は、指定された秒の実行を遅らせます。
構文
timeout <seconds> /nobreak
<seconds>
は、-1
から 100000
までの任意の値です。-1
を指定すると、コンピューターはキーストロークまで無期限に待機します。
/nobreak
はユーザーボタンを無視して、ボタンの影響を受けません。
timeout
例
timeout /t 5
次の実行の前に 5 秒間一時停止します。
ping
遅延を導入するコマンド
コマンド timeout
を使用すると、PC はコマンドの実行を数秒間停止しますが、それでもかなりの CPU 負荷を消費します。ループバックアドレス 127.0.0.1
を指定した ping
コマンドは連続する ping
の間に 1 秒の遅延がが発生し、CPU の負荷が少なくなります。
ping
遅延の例
ping -n 6 127.0.0.1>nul
6
は、遅延が 6-1=5
秒に設定されることを意味します。
>nul
は標準出力をパイプ null
にストリーミングするため、コンソールには何も表示されません。
Founder of DelftStack.com. Jinku has worked in the robotics and automotive industries for over 8 years. He sharpened his coding skills when he needed to do the automatic testing, data collection from remote servers and report creation from the endurance test. He is from an electrical/electronics engineering background but has expanded his interest to embedded electronics, embedded programming and front-/back-end programming.
LinkedIn