# How to exit Ruby program properly

**URL:** <https://www.ruby-forum.com/t/how-to-exit-ruby-program-properly/50109>\
**Category:** Ruby\
**Created:** [December 13, 2005, 4:57am UTC](https://www.ruby-forum.com/t/how-to-exit-ruby-program-properly/50109 "2005-12-13T04:57:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [December 13, 2005, 4:57am UTC](https://www.ruby-forum.com/t/how-to-exit-ruby-program-properly/50109/1 "2005-12-13T04:57:17Z")

</div>

I’m learning to write ruby code, and I’m using 1.8.2 on Windows XP.  
What is the best way to exit from my .rb script?

I’m using Process.exit but the documentation implies that it will throw  
an exception. So I’m guessing there’s a “cleaner” way to exit?

For example:

# test.rb

if ARGV.length == 0  
puts “Please specify a filename”  
Process.exit  
end

# script continues here…

Thanks!  
Jeff

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [December 13, 2005, 6:54am UTC](https://www.ruby-forum.com/t/how-to-exit-ruby-program-properly/50109/2 "2005-12-13T06:54:21Z")

</div>

Jeff C. wrote:

> I’m learning to write ruby code, and I’m using 1.8.2 on Windows XP.  
> What is the best way to exit from my .rb script?
> 
> I’m using Process.exit but the documentation implies that it will throw  
> an exception. So I’m guessing there’s a “cleaner” way to exit?

just to save you 3.5 seconds of searching, it’s Kernel.exit and exit!  
we’re talking about in the docs.

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [December 13, 2005, 6:30pm UTC](https://www.ruby-forum.com/t/how-to-exit-ruby-program-properly/50109/3 "2005-12-13T18:30:17Z")

</div>

Gene T. wrote:

> just to save you 3.5 seconds of searching, it’s Kernel.exit and exit!  
> we’re talking about in the docs.  
> Will this actually work if a Thread (unjoined) does it?  
> Should experiment before asking, but I am in the middle of something  
> else 🙂  
> Cheers,  
> V.-

–  
[http://www.braveworld.net/riva](http://www.braveworld.net/riva)
