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?
views:
325answers:
2
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
2010-03-02 16:46:58
+4
A:
Look at the help on the Wait-Process cmdlet:
man Wait-Process -full
start-process notepad -PassThru | Wait-Process
Keith Hill
2010-03-02 17:05:01
Here is another way: notepad; (ps notepad).WaitForExit()
Doug Finke
2010-03-03 00:16:38
That works fine, except that -PassThru wasn't recognised. Maybe because I'm still using v1.0?
Charles Anderson
2010-03-04 10:29:36
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
2010-03-04 14:59:37