更新
该
timeout命令,可以从Windows
Vista和以后应在命令中使用,如在另一所描述的回答了这个问题。接下来是一个_古老的_ 答案。
timeout从Windows Vista以后的版本中可以使用该命令:
c:> timeout /?TIMEOUT [/T] timeout [/NOBREAK]Description: This utility accepts a timeout parameter to wait for the specified time period (in seconds) or until any key is pressed. It also accepts a parameter to ignore the key press.Parameter List: /T timeout Specifies the number of seconds to wait. Valid range is -1 to 99999 seconds. /NOBREAK Ignore key presses and wait specified time. /?Displays this help message.NOTE: A timeout value of -1 means to wait indefinitely for a key press.Examples: TIMEOUT /? TIMEOUT /T 10 TIMEOUT /T 300 /NOBREAK TIMEOUT /T -1
注意:它不适用于输入重定向-简单示例:
C:>echo 1 | timeout /t 1 /nobreakERROR: Input redirection is not supported, exiting the process immediately.
旧答案
如果您安装了Python,或者不介意安装它(它也具有其他用途:),只需创建以下 sleep.py 脚本并将其添加到PATH中的某个位置即可:
import time, systime.sleep(float(sys.argv[1]))
如果您有此需要,它将允许亚秒级的暂停(例如1.5秒,0.1等)。如果您想将其称为
sleep而不是
sleep.py,则可以将
.PY扩展名添加到PATHEXT环境变量中。在Windows
XP上,您可以在以下位置进行编辑:
我的电脑→属性(菜单)→高级(选项卡)→环境变量(按钮)→系统变量(框架)



