"timeout - t" vs. "timeout" .有什么实际区别吗?



我一直在挑战自己,用尽可能少的字符重写我的一个批处理项目,并开始怀疑-t是否有任何用途。

显然,下面的两个脚本在执行时的行为方式完全相同。

timeout -t 5
echo test
pause
timeout 5
echo test
pause

两个microsoft文档(https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/timeout_1)和ss64(https://ss64.com/nt/timeout.html)不要提及-t是否必要。

timeout命令自己的/?帮助在括号中显示[/T],表示它是可选的。

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.
...

当给定无效参数时显示的错误消息也会提到/T,而不管它是否在命令行中实际指定。

C:>timeout ***
ERROR: Invalid value for timeout (/T) specified. Valid range is -1 to 99999.

可选的/T交换机可能是为了向后兼容,因为与NT4/2000资源工具包一起发布的timeout的早期版本没有/T作为交换机。例如,这是Windows 2000 Server Resource Kit Supplement 1中的timeout.exe

C:>dir C:etc*.exe | find /i "timeout"
12/02/1999  03:54 PM            62,464 TIMEOUT.EXE
C:>C:etctimeout /?
TIMEOUT - This utility is similar to the DOS PAUSE command.  However, it
accepts a timeout parameter to specify a length of wait (in seconds)
at which time it will continue without a key press.
Written by Eric Brown, Business System Division.
Copyright (C) Microsoft Corporation, 1992-1995.
Usage -   TIMEOUT <###>
where <###> is a decimal number of seconds between -1 and 100000.
The value -1 means to wait indefinitely for a key hit.

最新更新