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 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With