Return codes

Discussion in 'Ruby' started by Peter Hug, Mar 11, 2008.

  1. Peter Hug

    Peter Hug Guest

    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, Mar 11, 2008
    #1
    1. Advertising

  2. Peter Hug

    Tim Hunter Guest

    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
    Tim Hunter, Mar 11, 2008
    #2
    1. Advertising

  3. Peter Hug

    Peter Hug Guest

    Peter Hug, Mar 11, 2008
    #3
  4. 2008/3/11, Peter Hug <>:
    > 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

    --
    use.inject do |as, often| as.you_can - without end
    Robert Klemme, Mar 11, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gary
    Replies:
    3
    Views:
    540
    Steve Grazzini
    Sep 18, 2003
  2. Greg  --
    Replies:
    4
    Views:
    2,151
  3. Greenhorn
    Replies:
    15
    Views:
    807
    Keith Thompson
    Mar 6, 2005
  4. Replies:
    2
    Views:
    2,814
    Malcolm
    Aug 20, 2005
  5. Allen
    Replies:
    1
    Views:
    634
    Mark Rae [MVP]
    Dec 3, 2007
Loading...

Share This Page