From: Joel VanderWerf Date: 2007-04-06T04:05:08+09:00 Subject: Re: Rake and removing a capturing ^C Scott Taylor wrote: > > How can I remove such a trapping from a program? > > I'm running autotest through a rake task. Autotest uses ^C to restart > the tests, rake uses it to cancel the task at hand. > > What would be the best way to remove this trap from rake? I don't know if this will help without hacking into rake or autotest, but you can save and restore the handler. The return value of #trap is the previous handler, which is just a proc object: irb(main):001:0> oldh = trap("INT") {puts "newh"} => # irb(main):002:0> ### <-- I pressed ^C and Enter here newh irb(main):003:0* irb(main):004:0* newh = trap("INT", &oldh) => # irb(main):005:0> ^C There is also a useful special case. If you pass "DEFAULT" as the handler, you go back to ruby's default (which is different from irb's handler): irb(main):001:0> trap("INT", "DEFAULT") => # irb(main):002:0> ### <-- I pressed ^C and Enter here c:/ruby/lib/ruby/1.8/irb/input-method.rb:97:in `gets': Interrupt from c:/ruby/lib/ruby/1.8/irb.rb:132:in `eval_input' from c:/ruby/lib/ruby/1.8/irb.rb:259:in `signal_status' from c:/ruby/lib/ruby/1.8/irb.rb:131:in `eval_input' from c:/ruby/lib/ruby/1.8/irb/ruby-lex.rb:189:in `call' from c:/ruby/lib/ruby/1.8/irb/ruby-lex.rb:189:in `buf_input' from c:/ruby/lib/ruby/1.8/irb/ruby-lex.rb:104:in `getc' from c:/ruby/lib/ruby/1.8/irb/slex.rb:206:in `match_io' from c:/ruby/lib/ruby/1.8/irb/slex.rb:76:in `match' ... 8 levels... from c:/ruby/lib/ruby/1.8/irb.rb:70:in `start' from c:/ruby/lib/ruby/1.8/irb.rb:69:in `catch' from c:/ruby/lib/ruby/1.8/irb.rb:69:in `start' from c:/ruby/bin/irb.bat:20 Terminate batch job (Y/N)? y -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407