8
我會編寫一個腳本來運行程序並等待它完成。但是如果程序沒有在指定的時間內完成,我希望程序被終止。從PowerShell運行程序超時
我會編寫一個腳本來運行程序並等待它完成。但是如果程序沒有在指定的時間內完成,我希望程序被終止。從PowerShell運行程序超時
這是一個腳本來做到這一點。原始示例見Windows PowerShell Blog。
$p = [diagnostics.process]::start("notepad.exe")
if (! $p.WaitForExit(1000))
{ echo "Notepad did not exit after 1000ms"; $p.kill() }
在PowerShell 2.0上,你可以用'$ p = Start-Process Notepad -passthru'替換第一行, – 2009-11-17 15:13:22