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

use & instead of start-process in x.ps1 #118782

Merged
merged 1 commit into from
Dec 10, 2023
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
19 changes: 3 additions & 16 deletions x.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,16 @@ $ErrorActionPreference = "Stop"
Get-Command -syntax ${PSCommandPath} >$null

$xpy = Join-Path $PSScriptRoot x.py
# Start-Process for some reason splits arguments on spaces. (Isn't powershell supposed to be simpler than bash?)
# Double-quote all the arguments so it doesn't do that.
$xpy_args = @("""$xpy""")
foreach ($arg in $args) {
$xpy_args += """$arg"""
}
$xpy_args = @($xpy) + $args

function Get-Application($app) {
$cmd = Get-Command $app -ErrorAction SilentlyContinue -CommandType Application | Select-Object -First 1
return $cmd
}

function Invoke-Application($application, $arguments) {
$process = Start-Process -NoNewWindow -PassThru $application $arguments
# WORKAROUND: Caching the handle is necessary to make ExitCode work.
# See https://stackoverflow.com/a/23797762
$handle = $process.Handle
$process.WaitForExit()
if ($null -eq $process.ExitCode) {
Write-Error "Unable to read the exit code"
Exit 1
}
Exit $process.ExitCode
& $application $arguments
Exit $LASTEXITCODE
}

foreach ($python in "py", "python3", "python", "python2") {
Expand Down
Loading