【发布时间】:2013-09-14 16:52:40
【问题描述】:
我在 ruby 中有一堆系统调用,如下所示,我想同时检查它们的退出代码,以便在该命令失败时退出我的脚本。
system("VBoxManage createvm --name test1")
system("ruby test.rb")
我想要类似的东西
system("VBoxManage createvm --name test1", 0)
这可能吗?
我已经尝试过类似的方法,但也没有用。
system("ruby test.rb")
system("echo $?")
或
`ruby test.rb`
exit_code = `echo $?`
if exit_code != 0
raise 'Exit code is not zero'
end
【问题讨论】:
-
在上面的例子中,
exit_code将是一个字符串——"0\n"或"1\n",所以exit_code != 0将永远为真
标签: ruby command exit exit-code