Skip to content

Commit

Permalink
use & instead of start-process in x.ps1
Browse files Browse the repository at this point in the history
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 `&`.
  • Loading branch information
jyn514 committed Dec 9, 2023
1 parent 2b399b5 commit 2cf54e9
Showing 1 changed file with 3 additions and 16 deletions.
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

0 comments on commit 2cf54e9

Please sign in to comment.