2

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?

2 Answers 2

5

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"
Sign up to request clarification or add additional context in comments.

Comments

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.