Return error code from x.ps1

This commit is contained in:
Chris Denton 2023-05-03 16:06:16 +01:00
parent 82cd953c7c
commit 9ea7142a01
No known key found for this signature in database
GPG key ID: 713472F2F45627DE

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
}