From: Josh Cheek Date: 2011-02-02T23:15:01+09:00 Subject: Re: How to know the exit status within at_exit() block? --0016363b9d7a32a1cd049b4d46a6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Wed, Feb 2, 2011 at 4:46 AM, I=F1aki Baz Castillo wrote: > 2011/2/1 Eric Hodel : > >> Hi, my program invokes "exit true" or "exit false" and I want to catch > >> such return code into at_exit() block, but I don't know how to do > >> that. > > > > ruby -e 'at_exit { p $!.status }; exit 1' > > Really interesting. However, it fails if exit() is called outside of the > scope: > > irb> at_exit { p "$!.inspect =3D #{$!.inspect}" } > # > irb> exit 1 > "$!.inspect =3D nil" > > So $! is nil and I cannot get $!.status. > > > -- > I=F1aki Baz Castillo > > > It probably doesn't work in IRB, because IRB wraps calls to exit irb> method :exit =3D> # I think that using $! is probably what you should do. --0016363b9d7a32a1cd049b4d46a6--