1

I'm currently wrapping scripts with begin; rescue; end. Which works, but is annoying to un/comment at two different places and so on. Is there something like error_reporting(0); in PHP, but applied to the exit code and STDERR output?

2 Answers 2

2

You could try trapping the EXIT signal:

The special signal name "EXIT" or signal number zero will be invoked just prior to program termination.

Something like this should guarantee that your script always returns zero to the operating system:

Signal.trap('EXIT') { exit 0 }

For example, this script:

Signal.trap('EXIT') { exit 0 }
exit 1

actually returns zero to the OS despite triggering script's termination with exit 1.

Sign up to request clarification or add additional context in comments.

Comments

-1

Actually I did not understand what you are asking for. Here is the answer as I understand. But would be useful if you provide some more detail.

def
  some code...
rescue
  abort
end

1 Comment

abort does an exit(false) but OP is asking for the opposite, so instead of abort you may want to call exit or the more explicit exit(true).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.