Auto merge of #111141 - ChrisDenton:ps-exitcode, r=jyn514

Return error code from x.ps1

Fixes #111136

This works around a bug where `ExitCode` does not return the exit code. See: https://stackoverflow.com/a/23797762
This commit is contained in:
bors 2023-05-03 23:17:21 +00:00
commit f557a4fd46

7
x.ps1
View File

@ -16,7 +16,14 @@ 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
}