如何在 PowerShell 中使用 Timeout 命令?
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,它將終止整個指令碼執行。
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式語言
C++
C#
MongoDB
MySQL
JavaScript
PHP