How to pause a Powershell script until some external event has occurred?
-
23-09-2019 - |
Question
I am using a Powershell 1 script to kick off a Python program, and I want to then pause the Powershell until the Python has completed its work. (I have complete ownership of the Python file.) What is the best way to go about this?
Solution
Look at the help on the Wait-Process cmdlet:
man Wait-Process -full
start-process notepad -PassThru | Wait-Process
OTHER TIPS
you can get the Process object or ID with the get-process commandlet to get the process object or you can get it like I show below either will work.
you can use the PID and call
$proc = [System.Diagnostics.Process]::GetProcessById($PID)
while(-not $proc.HasExited) {[System.Threading.thread]::sleep(500) }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow