Return codes

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

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

···

------------------------------------------------------------------------
      Initiates the termination of the Ruby script by raising the
      SystemExit exception. This exception may be caught. The optional
      parameter is used to return a status code to the invoking
      environment.

--
RMagick: http://rmagick.rubyforge.org/
RMagick 2: http://rmagick.rubyforge.org/rmagick2.html

Perfect! Many thanks Tim.

···

--
Posted via http://www.ruby-forum.com/.

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