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 behaves differently in terminal vs ZMQ frontends #2794

Closed
takluyver opened this issue Jan 15, 2013 · 1 comment
Closed

_exit_code behaves differently in terminal vs ZMQ frontends #2794

takluyver opened this issue Jan 15, 2013 · 1 comment
Labels
Milestone

Comments

@takluyver
Copy link
Member

The ZMQ frontends (which use pexpect to run !foo shell commands) set _exit_code to the simple exit code of the process.

In the terminal, we use os.system, which on Unix-y systems returns:

exit status indication: a 16-bit number, whose low byte is the signal number that killed the process, and whose high byte is the exit status (if the signal number is zero); the high bit of the low byte is set if a core file was produced.

N.B. the docs also say:

Note that POSIX does not specify the meaning of the return value of the C system() function, so the return value of the Python function is system-dependent.

We should work out which systems this affects (i.e. do BSD & Macs do the same thing?) and do something sensible with the exit code.

@minrk
Copy link
Member

minrk commented Jan 15, 2013

OS X:

In [3]: os.system("true")
Out[3]: 0

In [4]: Popen("true", shell=True).wait()
Out[4]: 0

In [5]: os.system("false")
Out[5]: 256

In [6]: Popen("false", shell=True).wait()
Out[6]: 1

In [7]: os.system("notfound")
sh: notfound: command not found
Out[7]: 32512

In [8]: Popen("notfound", shell=True).wait()
/bin/sh: notfound: command not found
Out[8]: 127

Which suggests what you have described elsewhere - the return of os.system is 256 * returncode

@takluyver takluyver mentioned this issue Jan 17, 2013
minrk added a commit that referenced this issue Jan 18, 2013
fix `_exit_code` after running system calls

Correct the exit code to be a simple value, rather than two or three separate values stuffed into a single integer.

Closes #2794
minrk pushed a commit to minrk/ipython that referenced this issue Jan 26, 2013
minrk added a commit that referenced this issue Mar 5, 2013
Correct the exit code to be a simple value, rather than two or three separate values stuffed into a single integer.

Closes issue #2794.

My reading of the [Windows docs](http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/exit.mspx?mfr=true) is that the test I've added should work on Windows as well.
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014
fix `_exit_code` after running system calls

Correct the exit code to be a simple value, rather than two or three separate values stuffed into a single integer.

Closes ipython#2794
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants