使用 PowerShell 运行应用程序并等待它完成 [英] Run an application with PowerShell and wait until it is finished

查看:95
本文介绍了使用 PowerShell 运行应用程序并等待它完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 PowerShell 运行应用程序并等待它完成?例如,我想运行 Thunderbird 并在用户关闭它后,然后将某些内容打印到输出?

第二件事 - 是否可以像开始菜单中那样使用 thunderbird 关键字搜索此应用程序(当我们手动输入时,它会返回结果 Mozilla Thunderbird) -并运行它?

谢谢!

解决方案

您可以执行以下操作:

Start-Process myprogram.exe -NoNewWindow -Wait

或者如果你想要一个更简洁的机制,总是有 Out-Null hack:

myprogram.exe |出空

管道将等待程序终止,因此我们管道到 Out-Null

至于寻找应用程序,这个SO question涵盖了如何做这.这是另一篇文章,展示了 这个方法.

您可能还想看看这篇关于如何制作 Powershell 与 Windows 搜索交互这个,这是开始按钮使用的.>

Is it possible to run an application with PowerShell and wait until it is finished ? For example I want to run Thunderbird and after user closes it, then print something to the output ?

Second thing - is it possible to search for this application using thunderbird keyword like in Start Menu (when we type it manually, it returns a result Mozilla Thunderbird) - and also run it ?

Thanks !

解决方案

You can do something like:

Start-Process myprogram.exe -NoNewWindow -Wait

Or if you would like a more concise mechanism, there's always the Out-Null hack:

myprogram.exe | Out-Null

Piping will wait for the program to terminate, and hence we pipe to Out-Null

As for finding an app, this SO question covers how to do this. Here is another article demonstrating this method.

You might also want to look at this article on how to make Powershell interact with Windows Search and this one, which is what the Start Button uses.

这篇关于使用 PowerShell 运行应用程序并等待它完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆