开发者

Exit a Ruby script with status 0 on an exception

开发者 https://www.devze.com 2023-03-30 13:50 出处:网络
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_repo开发者_开发技巧rting(0); in PHP

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_repo开发者_开发技巧rting(0); in PHP, but applied to the exit code and STDERR output?


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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消