Skip to content

Commit 2cf54e9

Browse files
committed
use & instead of start-process in x.ps1
start-process has weird parsing rules and buggy behavior. we've already had to work around them several times, and the workarounds were not complete. i wonder who could have added it HMMMMMM ``` PS C:\Users\jyn\src\rust> git log --reverse -S Start-Process x.ps1 commit 775c3c0 Author: Jynn Nelson <github@jyn.dev> Date: Sun Jul 31 14:02:31 2022 -0500 Add `x.sh` and `x.ps1` shell scripts ``` the latest broken thing is trailing backslashes: ``` $ x.ps1 t .\tests\ui\error-emitter\ ``` would be transformed into ``` ['t', '.\\tests\\ui\\error-emitter"'] ``` rather than trying to hack around that too, abandon start-process altogether and just use `&`.
1 parent 2b399b5 commit 2cf54e9

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

x.ps1

+3-16
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,16 @@ $ErrorActionPreference = "Stop"
88
Get-Command -syntax ${PSCommandPath} >$null
99

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

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

2318
function Invoke-Application($application, $arguments) {
24-
$process = Start-Process -NoNewWindow -PassThru $application $arguments
25-
# WORKAROUND: Caching the handle is necessary to make ExitCode work.
26-
# See https://stackoverflow.com/a/23797762
27-
$handle = $process.Handle
28-
$process.WaitForExit()
29-
if ($null -eq $process.ExitCode) {
30-
Write-Error "Unable to read the exit code"
31-
Exit 1
32-
}
33-
Exit $process.ExitCode
19+
& $application $arguments
20+
Exit $LASTEXITCODE
3421
}
3522

3623
foreach ($python in "py", "python3", "python", "python2") {

0 commit comments

Comments
 (0)