tgrosinger
tgrosinger

Reputation: 2589

Powershell - Pause Script while External Program Runs

I am have a powershell script that does a few things that all need to be completed sequentially. Currently I am using this code to run a couple external programs (assume I am in the correct directory)

.\program1.exe
.\program2.exe
.\program3.exe

The problem I am having is that these will all run sequentially, not waiting until the previous one is finished. Is there a way to make them wait until the previous program ends?

Upvotes: 2

Views: 3949

Answers (2)

Malk
Malk

Reputation: 12003

(".\program1.exe", ".\program2.exe", ".\program3.exe") | % { & $_ }

Stick all the programs in array. Then run the array through a foreach loop that executes them.

Upvotes: 0

Andy Arismendi
Andy Arismendi

Reputation: 52699

Most processes will cause PowerShell to wait until their completion unless they do something funky, like Oracle's installers.

You could try:

Start-Process -FilePath program1.exe -Wait

If this doesn't work you might have do something like this:

& program1.exe 
while ($true) {
    Start-Sleep -Seconds 1
    if (-not (Get-Process -Name program1 -ErrorAction SilentlyContinue)) {
        break
    }
}
"...continue here"

Upvotes: 5

Related Questions