3 ms·
> Ruby is kind of clumsy for doing all the command piping parts of scripting, though; especially since there's no easy way short of wrapping Kernel.system in yo
by woodruffw 8y ago
> Ruby is kind of clumsy for doing all the command piping parts of scripting, though; especially since there's no easy way short of wrapping Kernel.system in your own function to make a Ruby script crash on a nonzero subshell exit status.
You can do this by checking `$?`, and wrapping that check in a small function:
def safer_system(*args)
system *args
raise "command failed with status: #{$?.exitstatus}" unless $?.success?
end
(It might be small consolation, but Ruby 2.6 is also adding `exception: true` to `Kernel#system`)[1].
[1]: https://bugs.ruby-lang.org/issues/14386 https://bugs.ruby-lang.org/issues/14386