Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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...

like image 304
Jonny Avatar asked Feb 01 '26 01:02

Jonny


2 Answers

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()
like image 77
Keith Hill Avatar answered Feb 03 '26 01:02

Keith Hill


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

like image 30
guillermooo Avatar answered Feb 03 '26 00:02

guillermooo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!