Forum: Ruby Ruby and capturing ^C

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
555c1193071e97926fa67c038244c047?d=identicon&s=25 Phy Prabab (Guest)
on 2007-04-05 07:33
(Received via mailing list)
Hello!

Is there any way to capture or "trap" ^C within Ruby?  Something similar
to shell "trapping" is what I am after so that I can do clean up in the
event ^C is pressed.

TIA!
Phy
E34b5cae57e0dd170114dba444e37852?d=identicon&s=25 Logan Capaldo (Guest)
on 2007-04-05 07:48
(Received via mailing list)
On 4/5/07, Phy Prabab <phyprabab@yahoo.com> wrote:
> Hello!
>
> Is there any way to capture or "trap" ^C within Ruby?  Something similar to shell 
"trapping" is what I am after so that I can do clean up in the event ^C is pressed.
>
> TIA!
> Phy
>
It's one thing when you don't know what to search for, but did you even
try?
http://www.google.com/search?hl=en&q=ruby+trap&btn...
A4a8fefcbd2cd6d2370609a5e2a3a389?d=identicon&s=25 Rob Merrell (Guest)
on 2007-04-05 08:12
(Received via mailing list)
This should do the trick:

trap("INT") do
    ...code block...
end

Rob
This topic is locked and can not be replied to.