使用超时从PowerShell运行程序

时间:2009-11-17 09:48:06

标签: powershell process timeout

我将编写一个运行程序的脚本并等待它完成。但是如果程序没有在指定的时间内完成,我希望程序被杀死。

1 个答案:

答案 0 :(得分:19)

这是一个执行此操作的脚本。有关原始示例,请参阅Windows PowerShell Blog

$p = [diagnostics.process]::start("notepad.exe")
if ( ! $p.WaitForExit(1000) ) 
  { echo "Notepad did not exit after 1000ms"; $p.kill() }