here's powershell code:
test.ps1:
. c:\path\to\test2.ps1 exit 5 test2.ps1:
exit 7 run test.ps1 standard command prompt run powershell scripts, call:
echo %errorlevel% the expected result return code of 7. first exit command in powershell script. actual result, however, return code of 5. included script terminated return code ignored , calling script happily continued.
how can terminate script , return result code no matter how called?
or alternatively, how should call test2.ps1 return code passed on outside world?
background: build script made powershell , includes module files different tasks. 1 task fails , build server didn't detect error because start build script still returned 0.
you should query $lastexitcode have nonzero value if last script/program exited failure. so, sample's test1.ps1 should this:
. c:\path\to\test2.ps1 if ($lastexitcode -ne 0) { exit $lastexitcode} exit 5
Comments
Post a Comment