ruby system command check exit code

后端 未结 5 544
太阳男子
太阳男子 2020-12-02 12:39

I have a bunch of system calls in ruby such as the following and I want to check their exit codes simultaneously so that my script exits out if that command fails.



        
5条回答
  •  有刺的猬
    2020-12-02 13:30

    system returns false if the command has an non-zero exit code, or nil if there is no command.

    Therefore

    system( "foo" ) or exit
    

    or

    system( "foo" ) or raise "Something went wrong with foo"
    

    should work, and are reasonably concise.

提交回复
热议问题