在超时的情况下从 PowerShell 运行程序 [英] Run a program from PowerShell with timeout
本文介绍了在超时的情况下从 PowerShell 运行程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将编写一个脚本来运行一个程序并等待它完成.但是如果程序没有在指定的时间内完成,我希望程序被杀死.
I'll write a script that runs a program and wait for it finished. But if the program is not finished within a specified time I want that the program is killed.
推荐答案
这是执行此操作的脚本.请参阅 Windows PowerShell 博客,了解原始示例.
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() }
这篇关于在超时的情况下从 PowerShell 运行程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文