IPython - Enhanced Interactive Python

magic to return exit status

Reported by benholroyd on 2009-04-23
2
Affects Status Importance Assigned to Milestone
IPython
Confirmed
Wishlist
Unassigned

Bug Description

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.

Fernando Perez (fdo.perez) 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 0.10, and likely post 0.11, since I'm sure the magic reorg will take some serious effort.

Changed in ipython:
importance: Undecided → Wishlist
status: New → Confirmed

On Thu, Apr 23, 2009 at 10:18 PM, Fernando Perez <email address hidden> 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

Fernando Perez (fdo.perez) wrote :

On Thu, Apr 23, 2009 at 12:36 PM, Ville M. Vainio <email address hidden> wrote:
> On Thu, Apr 23, 2009 at 10:18 PM, Fernando Perez <email address hidden>
> 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

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers