How to Capture Signal on Ruby Running on Windows

How do I pick up a signal on a ruby ​​running on windows?

I want to send a signal / message from a C ++ application to a ruby ​​script.

+1


a source to share


3 answers


Signal.list tells you which ones are supported on your system.



+1


a source


Look at the Signal Module . The documentation has a pretty good example at the very top.



+2


a source


It depends on the signal. If you want to catch ctrl-C this works on Windows. Many signals (sigup1, sigusr1, etc.) don't really work on Windows (at least not for me). Here's how to catch ctrl-C. In this example, I just type a message and exit the application. You can pass any proc object to the signal manager - be sure to pay attention to the scope if you read / edit variables inside the proc:

trap("INT") { puts "\nExiting"; exit;}

      

+2


a source







All Articles