I’m using the PowerShell syntax:
Start-Process -FilePath $file -ArgumentList $argList -NoNewWindow -Wait
The process being started is an installer, which installs a Windows service and then starts up that service, then the process stops. What’s happening is that my script is hanging indefinitely, even after the process completed successfully and the process has exited (as I can see in Task Manager. When I run it from a command line, without PowerShell, it’s done in under a minute). Apparently, it’s still waiting because there’s a child process which was spawned from the original process. How can I tell PowerShell to wait only for the initial process ($file) and not any children?
In the end, I decided to simply do it the .NETy way, even though I had preferred a Powershelly way of doing it. Code below is copied from https://stackoverflow.com/a/8762068/1378356:
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = $file
$pinfo.UseShellExecute = $false
$pinfo.Arguments = $argList
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
Write-Host "exit code: " + $p.ExitCode
This way worked without issue.