Skip to content

Instantly share code, notes, and snippets.

@vladzloteanu
Created February 15, 2012 09:31
Show Gist options
  • Save vladzloteanu/1834755 to your computer and use it in GitHub Desktop.
Save vladzloteanu/1834755 to your computer and use it in GitHub Desktop.
[ruby] run shell command, read output (from Bundler code)
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