Skip navigation
Forcing PowerShell to Wait for a Process to Complete

Forcing PowerShell to Wait for a Process to Complete

Use the power of the Out-null cmdlet to simulate the old Start/Wait command used for batch files. 

Those who were once used to writing batch files will like this tip. In the old days, using the old ways, you could use the Start/Wait command in batch files to cause the script to pause, wait for a process to complete, and then move on to the next steps in the script.

You can do the same thing with PowerShell using the Out-null cmdlet. Out-null actually deletes output instead of routing it to the PowerShell console, so the script will sit and wait for the content to be deleted before moving on.

This will work with practically any process you choose.  Just stick the following at the end of the line (notice the pipe character before the command):

| out-null

To test this out for yourself, create a text file and then use Notepad.exe to open the file:

Notepad.exe myfile.txt | out-null

 

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish