diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2023-12-09 18:00:38 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-09 18:00:38 +0100 |
| commit | dd234696ed202d133eabbbeef588fde11020ea14 (patch) | |
| tree | f80903214ba17b28a45af134eee1ea9d926e6a6c | |
| parent | 034d73d6d7b1cbc654fea336ccc3e4170f7af043 (diff) | |
| parent | 2cf54e9f99f83e314256808b1e0753779d49e652 (diff) | |
| download | rust-dd234696ed202d133eabbbeef588fde11020ea14.tar.gz rust-dd234696ed202d133eabbbeef588fde11020ea14.zip | |
Rollup merge of #118782 - jyn514:powershell, r=ChrisDenton
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 775c3c0493e9a383a7f1c521b06d36f2e3d0d886
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 `&`.
r? `@ChrisDenton`
| -rwxr-xr-x | x.ps1 | 19 |
1 files changed, 3 insertions, 16 deletions
diff --git a/x.ps1 b/x.ps1 index eae1a2cb399..afd988e67e4 100755 --- a/x.ps1 +++ b/x.ps1 @@ -8,12 +8,7 @@ $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 @@ -21,16 +16,8 @@ function Get-Application($app) { } 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") { |
