Skip to content

Commit f557a4f

Browse files
committed
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
2 parents 473f916 + 9ea7142 commit f557a4f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

x.ps1

+7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ function Get-Application($app) {
1616

1717
function Invoke-Application($application, $arguments) {
1818
$process = Start-Process -NoNewWindow -PassThru $application $arguments
19+
# WORKAROUND: Caching the handle is necessary to make ExitCode work.
20+
# See https://stackoverflow.com/a/23797762
21+
$handle = $process.Handle
1922
$process.WaitForExit()
23+
if ($null -eq $process.ExitCode) {
24+
Write-Error "Unable to read the exit code"
25+
Exit 1
26+
}
2027
Exit $process.ExitCode
2128
}
2229

0 commit comments

Comments
 (0)