fix: preserve sys.exit() exit codes in non-interactive mode by Sarah-2003 · Pull Request #15158 · ipython/ipython

added 2 commits

March 15, 2026 20:54
When running `ipython -c "import sys;sys.exit(2)"`, IPython incorrectly
returned exit code 1 instead of 2. The exit code was hardcoded to 1 in
the start() method of TerminalIPythonApp regardless of the actual code
passed to sys.exit().

Extract the original exit code from the stored SystemExit exception in
last_execution_result.error_in_exec. Also handle SystemExit separately
in the file execution path in _run_cmd_line_code().

Fixes ipython#15132
sys.exit() should exit quietly, not print a traceback. The bare except
handler below still shows tracebacks for actual errors.