Created
February 28, 2013 06:53
-
-
Save nexussays/5054793 to your computer and use it in GitHub Desktop.
Calling an external command (useful for build scripts)
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 run(command, abort_on_failure = true) | |
command.strip! | |
puts "> #{command}" if !block_given? | |
IO.popen("#{command} 2>&1") do |proc| | |
while !proc.closed? && (line = proc.gets) | |
if block_given? | |
yield line | |
else | |
puts "> #{line}" | |
end | |
end | |
end | |
if $?.exitstatus != 0 | |
msg = "Operation exited with status #{$?.exitstatus}" | |
raise msg if abort_on_failure | |
end | |
return $? | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment