views:

325

answers:

2

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?

A: 

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) }
rerun
+4  A: 

Look at the help on the Wait-Process cmdlet:

man Wait-Process -full
start-process notepad -PassThru | Wait-Process
Keith Hill
Here is another way: notepad; (ps notepad).WaitForExit()
Doug Finke
That works fine, except that -PassThru wasn't recognised. Maybe because I'm still using v1.0?
Charles Anderson
In that case, you are probably using the PSCX version of Start-Process which passes through by default. Although, Wait-Process is new in PowerShell 2.0. So my guess is that you are using 2.0 (if so, $psversiontable will be non-null) and that you are getting the PSCX version of Start-Process.
Keith Hill