# Return codes

**URL:** <https://rubytalk.org/t/return-codes/45086>\
**Category:** ruby-talk\
**Created:** [11 March 2008 00:33 UTC](https://rubytalk.org/t/return-codes/45086 "2008-03-11T00:33:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Hug](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@Peter\_Hug](https://rubytalk.org/u/Peter_Hug)\
**Post date:** [11 March 2008 00:33 UTC](https://rubytalk.org/t/return-codes/45086/1 "2008-03-11T00:33:31Z")

</div>

I'd like to be able to launch a little ruby application from within a  
shell script or a windows command file. How can my Ruby application  
return error or success codes such that the callee can verify the result  
easily both in Linux and Windows?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Tim\_Hunter4](https://avatars.discourse-cdn.com/v4/letter/t/ea5d25/32.png) [@Tim\_Hunter4](https://rubytalk.org/u/Tim_Hunter4)\
**Post date:** [11 March 2008 00:43 UTC](https://rubytalk.org/t/return-codes/45086/2 "2008-03-11T00:43:39Z")

</div>

Peter Hug wrote:

> I'd like to be able to launch a little ruby application from within a  
> shell script or a windows command file. How can my Ruby application  
> return error or success codes such that the callee can verify the result  
> easily both in Linux and Windows?

$ ri Kernel#exit  
------------------------------------------------------------ Kernel#exit  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(integer=0)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Kernel::exit(integer=0)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Process::exit(integer=0)

> **···**
>
> ------------------------------------------------------------------------  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Initiates the termination of the Ruby script by raising the  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SystemExit exception. This exception may be caught. The optional  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;parameter is used to return a status code to the invoking  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;environment.
> 
> --  
> RMagick: [http://rmagick.rubyforge.org/](http://rmagick.rubyforge.org/)  
> RMagick 2: [http://rmagick.rubyforge.org/rmagick2.html](http://rmagick.rubyforge.org/rmagick2.html)

---

<div class="post-metadata">

**Author:** ![Peter\_Hug](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@Peter\_Hug](https://rubytalk.org/u/Peter_Hug)\
**Post date:** [11 March 2008 08:39 UTC](https://rubytalk.org/t/return-codes/45086/3 "2008-03-11T08:39:48Z")

</div>

Perfect! Many thanks Tim.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Robert\_K1](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/robert_k1/32/1830_2.png) [@Robert\_K1](https://rubytalk.org/u/Robert_K1)\
**Post date:** [11 March 2008 17:08 UTC](https://rubytalk.org/t/return-codes/45086/4 "2008-03-11T17:08:13Z")

</div>

Additional note: it is sufficient to throw an exception or not. Ruby  
will automatically set the exit code appropriately:

18:06:55 /cygdrive/c/SCMws/Tickets/oz-26255\_no\_txid  
$ ruby -e '123'; echo $?  
0  
18:07:03 /cygdrive/c/SCMws/Tickets/oz-26255\_no\_txid  
$ ruby -e 'raise "foo"'; echo $?  
-e:1: foo (RuntimeError)  
1  
18:07:06 /cygdrive/c/SCMws/Tickets/oz-26255\_no\_txid  
$

Kind regards

robert

> **···**
>
> 2008/3/11, Peter Hug \<pete@kapiti.co.nz\>:
> 
> > Perfect! Many thanks Tim.
> 
> --  
> use.inject do |as, often| as.you\_can - without end
