1

I'm running some python code that is exiting via sys.exit(1) when failures occur. However, PowerShell (which is calling this code) doesn't terminate, even though I've told it to.

Example code that illustrates the issue:


python -c "import sys; sys.exit(1)"
Write-Host "The exit code is $LASTEXITCODE -- why is this running?"

What am I missing here?

I'm launching the code via:

.\test.ps1

(for example)

PowerShell version:

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      18362  145
Mike Crowe
  • 2,203
  • 3
  • 22
  • 37
  • 1
    In short: `$ErrrorActionPreference` has no effect on calling _external programs_; check `$LASTEXITCODE` to determine success vs. failure and report an error in response; see [the linked answer](https://stackoverflow.com/a/48877892/45375) for details. – mklement0 Apr 24 '20 at 14:55

0 Answers0