How to pause a Powershell script until some external event occurs?

I am using Powershell 1 script to run a Python program, and I want to pause Powershell until Python shuts down. (I completely own the Python file.) What is the best way to do this?

+4
source share
2 answers

Take a look at the help of the Wait-Process cmdlet:

man Wait-Process -full start-process notepad -PassThru | Wait-Process 
+6
source

you can get the Process object or ID using the get-process command to get the process object, or you can get it as shown below, or it will work.

you can use PID and call

 $proc = [System.Diagnostics.Process]::GetProcessById($PID) while(-not $proc.HasExited) {[System.Threading.thread]::sleep(500) } 
-1
source

Source: https://habr.com/ru/post/1302887/


All Articles