magic to return exit status #110

Closed
ipython opened this Issue May 10, 2010 · 4 comments

Comments

Projects
None yet
2 participants
@ghost

ghost commented May 10, 2010

Original Launchpad bug 365553: https://bugs.launchpad.net/ipython/+bug/365553
Reported by: ben-holroyd-1 (benholroyd).

what im suggesting is basically something similar to $? in bash to get the exit status, both for magic functions, and normal programs run through the shell.

At the moment there isn't a way (that ive discoved) of checking if a magic function successfully did what it was supposed to, and no way of returning an exit status without it displaying on screen.
example: i wrote a magic to cd to a directory and ls its contents (cdl), the obvious way would be to use the existing cd command, except you can't test if its run successfully.

i know you can use the subprocess or commands module to get exit codes but its not straight forward and has the disadvantage that you can't check after the fact if a program exited successfully.

anyway thank great program, i basically use it as my default shell now.

@ghost

ghost commented May 10, 2010

[ LP comment 1 by: Fernando Perez, on 2009-04-23 19:18:26.295238+00:00 ]

This is a very reasonable request. Probably best considered once we refactor the magics so they all share a base class, where this behavior can be implemented in a consistent manner. So this is at least post 0.10, and likely post 0.11, since I'm sure the magic reorg will take some serious effort.

@ghost

ghost commented May 10, 2010

[ LP comment 2 by: Ville M. Vainio, on 2009-04-23 19:36:21+00:00 ]

On Thu, Apr 23, 2009 at 10:18 PM, Fernando Perez fperez.net@gmail.com wrote:

This is a very reasonable request.  Probably best considered once we
refactor the magics so they all share a base class, where this behavior
can be implemented in a consistent manner.  So this is at least post

Actually, this is not a problem even now. ipmagic() can easily just
store the return value to some variable. The same variably could be
used to store _ip.system exit value.

Ville M. Vainio
http://tinyurl.com/vainio

@ghost

ghost commented May 10, 2010

[ LP comment 3 by: Fernando Perez, on 2009-04-23 19:50:38+00:00 ]

On Thu, Apr 23, 2009 at 12:36 PM, Ville M. Vainio vivainio@gmail.com wrote:

On Thu, Apr 23, 2009 at 10:18 PM, Fernando Perez fperez.net@gmail.com
wrote:

This is a very reasonable request.  Probably best considered once we
refactor the magics so they all share a base class, where this behavior
can be implemented in a consistent manner.  So this is at least post

Actually, this is not a problem even now. ipmagic() can easily just
store the return value to some variable. The same variably could be
used to store _ip.system exit value.

Feel free to toss the discussion over on the mailing list, so we can
get input from others. My reasons for wanting to be careful is that
I'd like an organized mechanism for coherently handling magics,
aliases and system calls. So at least we should get feedback on this
bug from the rest of the team to agree on a convention.

It's also important that magics be allowed to propagate an exception
if they want, yet we want to record the failure in this special
variable.

I'm all for solving this quickly, as long as we have a clean and
long-lived solution, not yet another quick hack that's a special case.

Cheers,

f

minrk closed this in 6c66e2b May 27, 2011

Owner

minrk commented May 27, 2011

closing this, as the _exit_code value in user_ns now stores the last ec of a call made via shell.system() (a la $?). It's not a magic, but the functionality is provided.

If desired, an %ec magic that returns this value would be trivial.

@mattvonrocketstein mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014

@minrk minrk Merge PR #459 (issue 297)
closes gh-110
closes gh-459
fd0222e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment