Stop execution of Ruby script
RubyRuby Problem Overview
Is there a method like exit
or die
in PHP which stops the execution of a Ruby script?
Ruby Solutions
Solution 1 - Ruby
Solution 2 - Ruby
abort
is an alias for Kernel.exit(false)
which terminates execution immediately.
exit
is an alias for Kernel.exit(true)
and raises the SystemExit
exception, that may be caught. Also at_exit
functions and finalizers
are run before termination.
Solution 3 - Ruby
abort
can still hang if there's threads that are waiting. If you really want to terminate immediately try:
Process.kill 9, Process.pid
Solution 4 - Ruby
FYI for ruby on rails, you can simply use this gem
shutup
,
in the rails directory run this command in the bash terminal
gem install shutup
it will find the PID of rails server and kill it.
and also you can do it with lsof -wi tcp:3000
in case you didnt start the server on another port otherwise you should change the port 3000