The following script mimics a situation in which a Python program exits with an error code other than zero:
#!/usr/bin/env python3
import sys
def foo():
try:
print(f"1/0={1/0}")
except ZeroDivisionError as exception:
print(f"Error: {exception}", file=sys.stderr)
sys.exit(1)
if __name__ == '__main__':
foo()
In PowerShell there are the LASTEXITCODE and $? special variables to read the exit code of the last program but it still reads 0 (or False) when I run the aforementioned Python script. I found an answer on SO that might shed more light on the situation [1], but I am a little bit lost what the terms native or Windows-based mean in this context. From my understanding, this definition doesn't include Python scripts?