Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Powershell: Use WaitForExit instead of -Wait #106216

Merged
merged 2 commits into from
Dec 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions x.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ function Get-Application($app) {
return Get-Command $app -ErrorAction SilentlyContinue -CommandType Application
}

function Invoke-Application($application, $arguments) {
$process = Start-Process -NoNewWindow -PassThru $application $arguments
$process.WaitForExit()
Exit $process.ExitCode
}

foreach ($python in "py", "python3", "python", "python2") {
# NOTE: this only tests that the command exists in PATH, not that it's actually
# executable. The latter is not possible in a portable way, see
Expand All @@ -23,16 +29,14 @@ foreach ($python in "py", "python3", "python", "python2") {
# Use python3, not python2
$xpy_args = @("-3") + $xpy_args
}
$process = Start-Process -NoNewWindow -Wait -PassThru $python $xpy_args
Exit $process.ExitCode
Invoke-Application $python $xpy_args
}
}

$found = (Get-Application "python*" | Where-Object {$_.name -match '^python[2-3]\.[0-9]+(\.exe)?$'})
if (($null -ne $found) -and ($found.Length -ge 1)) {
$python = $found[0]
$process = Start-Process -NoNewWindow -Wait -PassThru $python $xpy_args
Exit $process.ExitCode
Invoke-Application $python $xpy_args
}

Write-Error "${PSCommandPath}: error: did not find python installed"
Expand Down