Created
February 15, 2012 09:31
-
-
Save vladzloteanu/1834755 to your computer and use it in GitHub Desktop.
[ruby] run shell command, read output (from Bundler code)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sh(cmd, &block) | |
out, code = sh_with_code(cmd, &block) | |
code == 0 ? out : raise(out.empty? ? "Running `#{cmd}' failed. Run this command directly for more detailed output." : out) | |
end | |
def sh_with_code(cmd, &block) | |
cmd << " 2>&1" | |
outbuf = '' | |
Bundler.ui.debug(cmd) | |
Dir.chdir(base) { | |
outbuf = `#{cmd}` | |
if $? == 0 | |
block.call(outbuf) if block | |
end | |
} | |
[outbuf, $?] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment