# Return codes

**URL:** <https://www.ruby-forum.com/t/return-codes/131533>\
**Category:** Ruby\
**Created:** [March 11, 2008, 1:33am UTC](https://www.ruby-forum.com/t/return-codes/131533 "2008-03-11T01:33:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tekhne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90ced4/32.png) [@tekhne](https://www.ruby-forum.com/u/tekhne)\
**Post date:** [March 11, 2008, 1:33am UTC](https://www.ruby-forum.com/t/return-codes/131533/1 "2008-03-11T01:33:37Z")

</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?

---

<div class="post-metadata">

**Author:** ![tekhne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90ced4/32.png) [@tekhne](https://www.ruby-forum.com/u/tekhne)\
**Post date:** [March 11, 2008, 1:44am UTC](https://www.ruby-forum.com/t/return-codes/131533/2 "2008-03-11T01:44:25Z")

</div>

Peter H. 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  
exit(integer=0)  
Kernel::exit(integer=0)  
Process::exit(integer=0)

---

<div class="post-metadata">

**Author:** ![tekhne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90ced4/32.png) [@tekhne](https://www.ruby-forum.com/u/tekhne)\
**Post date:** [March 11, 2008, 9:39am UTC](https://www.ruby-forum.com/t/return-codes/131533/3 "2008-03-11T09:39:09Z")

</div>

Perfect! Many thanks Tim.

---

<div class="post-metadata">

**Author:** ![tekhne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90ced4/32.png) [@tekhne](https://www.ruby-forum.com/u/tekhne)\
**Post date:** [March 11, 2008, 6:13pm UTC](https://www.ruby-forum.com/t/return-codes/131533/4 "2008-03-11T18:13:14Z")

</div>

2008/3/11, Peter H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Perfect! Many thanks Tim.

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
