Whenever you want to execute something on the command line, you can use the following syntax:
%x(command to run)
However, I want to catch a
So this doesn't directly answer your question (won't capture the command's output). But instead of trying begin
/rescue
, you can just check the exit code ($?
) of the command:
%x(command to run)
unless $? == 0
"ack! error occurred"
end
Edit: Just remembered this new project. I think it does exactly what you want:
https://github.com/envato/safe_shell