如何在 PowerShell 中使用超时命令?
Timeout.exe实际上是一个cmd 命令,它也可以在PowerShell中使用。让我们看看与Timeout命令相关的帮助。
timeout /?
如果我们看到超时参数列表,我们可以使用 /T 表示以秒为单位的时间和/NoBreak命令,它忽略指定时间的任何键。
示例
Write-Output "Timeout is for 10 seconds" Timeout /T 10 Write-Output "This line will be executed after 10 seconds if not interuptted"输出结果
PS C:\> C:\Temp\TestPS1.ps1 Timeout is for 10 seconds Waiting for 5 seconds, press a key to continue ...
请注意:在上面的例子中,用户可以使用任意键来中断超时秒数来禁止用户中断使用/NoBreak开关。
示例
Write-Output "Timeout is for 10 seconds" Timeout /NoBreak 10 Write-Output "This line will be executed after 10 seconds"输出结果
PS C:\> C:\Temp\TestPS1.ps1 Timeout is for 10 seconds Waiting for 2 seconds, press CTRL+C to quit ...
如果输入 Ctrl+C,它将终止整个脚本执行。
热门推荐
1 训练狗狗基础
2 怎么训练狗狗笑
3 怎么训练狗狗卧下
4 上海狗狗训练基地
5 训练狗狗排便
6 狗狗基础训练
8 如何训练狗狗装死
9 狗狗站姿训练
10 狗狗训练用品
11 训练狗狗吧
12 狗狗要怎么训练
13 怎么训练狗狗玩球
14 训练狗狗唤回
15 狗狗训练躺下
16 狗狗训练指令
17 狗狗的训练技巧
18 狗狗不好训练