Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exit code #2799

Merged
merged 2 commits into from
Jan 18, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions IPython/core/interactiveshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -2246,6 +2246,10 @@ def system_raw(self, cmd):
else:
cmd = py3compat.unicode_to_str(cmd)
ec = os.system(cmd)
# The high byte is the exit code, the low byte is a signal number
# that we discard for now. See the docs for os.wait()
if ec > 255:
ec >>= 8

# We explicitly do NOT return the subprocess status code, because
# a non-None value would trigger :func:`sys.displayhook` calls.
Expand Down
5 changes: 5 additions & 0 deletions IPython/core/tests/test_interactiveshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,11 @@ def test_1(self):
"""
cmd = ur'''python -c "'åäö'" '''
ip.system_raw(cmd)

def test_exit_code(self):
"""Test that the exit code is parsed correctly."""
ip.system_raw('exit 1')
self.assertEqual(ip.user_ns['_exit_code'], 1)

class TestModules(unittest.TestCase, tt.TempFileMixin):
def test_extraneous_loads(self):
Expand Down