从 PowerShell 运行程序并超时

发布于 2024-08-11 08:25:27 字数 52 浏览 2 评论 0原文

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋叶绚丽 2024-08-18 08:25:27

这是一个执行此操作的脚本。请参阅 Windows PowerShell 博客了解原来的例子。

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

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() }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文