PowerShell – wait for completion of external process

Often when working with PowerShell you want to start an external process and wait for its completion. An example of this might look like this:

Write-Host "Show before starting Notepad"

Notepad.exe

Write-Host "Show after closing Notepad"

But this script prints the second line directly after starting notepad. There are several solutions possible, but this one has proved very useful.

Write-Host "Show before starting Notepad"

Notepad.exe | Out-Null

Write-Host "Show after closing Notepad"

Simply add Out-Null after the invocation of notepad and PowerShell will wait until it continues executing the script.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s