Ruby Program dont STOP

Hi, I’m new in Ruby and i found a little problem, make a simple program
with a infinite loop to print one String. I use linux (Kubuntu) and when
i try stop the program whit CTRL+C nothing happen the program dont stop
only when i execute the KILL command the program stop.
I do something wrong ?? How to solve this ?

Magician W. wrote:

Hi, I’m new in Ruby and i found a little problem, make a simple program
with a infinite loop to print one String. I use linux (Kubuntu) and when
i try stop the program whit CTRL+C nothing happen the program dont stop
only when i execute the KILL command the program stop.
I do something wrong ?? How to solve this ?

Check on your terminal if there is any key binding for CRTL+C like “Copy
to Clipboard”.

Joachim G. wrote:

Magician W. wrote:

Hi, I’m new in Ruby and i found a little problem, make a simple program
with a infinite loop to print one String. I use linux (Kubuntu) and when
i try stop the program whit CTRL+C nothing happen the program dont stop
only when i execute the KILL command the program stop.
I do something wrong ?? How to solve this ?

Check on your terminal if there is any key binding for CRTL+C like “Copy
to Clipboard”.

No CTRL+C stop processes i use it in all other programs.
Only with Ruby dont work.

Magician W. wrote:

No CTRL+C stop processes i use it in all other programs.
Only with Ruby dont work.

cat loop.rb

while true do
puts “test”
sleep 1
end

ruby loop.rb

test
test
loop.rb:3:in `sleep’: Interrupt
from loop.rb:3

One single CTRL+C works fine for me here. I’m using the XFCE terminal.

Philipp H. wrote:

hi,

instead of working with an infinite loop, you could trap the Crtl-C
signal to make your loop come to an end.

stop = false
trap(‘INT’) { stop = true }

until stop
# do your string stuff
end

g phil

Work perfect :smiley:
Where can i find more info about the trap command ?

hi,

instead of working with an infinite loop, you could trap the Crtl-C
signal to make your loop come to an end.

stop = false
trap(‘INT’) { stop = true }

until stop
# do your string stuff
end

g phil

Where can i find more info about the trap command ?

I believe with “ri”

If you dont know ri, look here
http://ruby.about.com/od/gettingstarted/qt/ruby_ri.htm