Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using start-process and -wait command in Powershell

Tags:

powershell

I am new to Powershell and don't have much of a programming background, just trying to use it for software packaging. Anyway, I found out about the start-process command with the -Wait parameter, and it works great for most things. What I noticed though is that not only does it wait for the process you specify, it waits for any sub processes, even after the main process is no longer running. Usually this is good, but I have a weird situation. I am running a complex Oracle batch file with start-process. The batch file eventually runs setup.exe which is what I really want to wait for, but other processes spawn too that never stop. So if I use the -wait parameter, the script never stops even after setup.exe is no longer running. The closest I've found is using this:

saps -FilePath "Path\config.bat" -ArgumentList "arguments"
Start-Sleep -s 10
Wait-Process -Name "setup"

This works, but I would think there'd be a better way without having to use a timeout command. Any ideas?

like image 970
Chris Avatar asked Nov 01 '16 13:11

Chris


Video Answer


1 Answers

Using Start-Process, there's an option for waiting:

Start-Process -Wait -FilePath "do_things.exe" -ArgumentList "argument another_argument"
like image 57
Jay Avatar answered Oct 03 '22 15:10

Jay