开发者

Run a program from PowerShell with timeout

开发者 https://www.devze.com 2022-12-12 05:00 出处:网络
I\'ll write a script that runs a program and wait开发者_C百科 for it finished. But if the program is not finished within a specified time I want that the program is killed.Here is a script which does

I'll write a script that runs a program and wait开发者_C百科 for it finished. But if the program is not finished within a specified time I want that the program is killed.


Here is a script which does that. See Windows PowerShell Blog for the original example.

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

精彩评论

暂无评论...
验证码 换一张
取 消