#PSTip Wait for executable to finish

Sometimes you need to wait for an executable to finish its job. The typical case is a Setup.exe, but this behavior is also ideal candidate for cleaning up temporary files after an application has been closed. Powershell makes this easy; just redirect the output to a (valid) pipe.

& 'C:\Program Files\Internet Explorer\iexplore.exe' | echo "Waiting."
"Internet Explorer has been closed."

Please notice that the invoke operator ‘&’ is used, and that the “Waiting.” message is not shown in the Powershell output.

The typical case is waiting for setup.exe or msiexec.exe to finish, but the behavior is also useful for tasks like cleaning up temporary files or starting external applications one after another.

Share on:
comments powered by Disqus