Skip to content

Instantly share code, notes, and snippets.

@nexussays
Created February 28, 2013 06:53
Show Gist options
  • Save nexussays/5054793 to your computer and use it in GitHub Desktop.
Save nexussays/5054793 to your computer and use it in GitHub Desktop.
Calling an external command (useful for build scripts)
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