开发者

Suspending a PowerShell script until a action is complete i.e. opening & closing Notepad

开发者 https://www.devze.com 2022-12-17 14:01 出处:网络
Is there a way of suspending a PowerShell script until some action has been completed. For example if I was using a Linux shell and I typed gedit then gedit would load but the shell would be suspended

Is there a way of suspending a PowerShell script until some action has been completed. For example if I was using a Linux shell and I typed gedit then gedit would load but the shell would be suspended until I closed gedit (unless '&' was added to the end of the command).

Is 开发者_JS百科there anyway to mimick this behaviour with PowerShell? So could I get a script to open Notepad but suspend itself until Notepad was closed again.

Thanks...


Just pipe to Out-Null and PowerShell will wait until the windows app closes:

PS> notepad | out-null

Or as the previous poster points out:

PS> (Start-Process notepad -PassThru).WaitForExit()


You need to use the System.Diagnostics.Process class and call the .WaitForExit method after setting the appropriate ProcessInfo properties to launch Notepad.

0

精彩评论

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

关注公众号