我在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
https://stackoverflow.com/questions/18728069
复制相似问题