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.
Phy P. (Guest)
on 2007-04-05 09: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
Logan C. (Guest)
on 2007-04-05 09:48
(Received via mailing list)
On 4/5/07, Phy P. <removed_email_address@domain.invalid> 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...
Rob M. (Guest)
on 2007-04-05 10: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.