diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 0cf351ba2a..9c88c8d710 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -216,20 +216,24 @@ protected # Pretty titles the command and buffers stdout/stderr # Throws if there's an error def system cmd, *args - full="#{cmd} #{args*' '}".strip - ohai full + ohai "#{cmd} #{args*' '}".strip + if ARGV.verbose? safe_system cmd, *args else - out='' - # TODO write a ruby extension that does a good popen :P - IO.popen "#{full} 2>&1" do |f| - until f.eof? - out+=f.gets - end + rd, wr = IO.pipe + fork do + rd.close + $stdout.reopen wr + $stderr.reopen wr + exec cmd, *args end - unless $? == 0 - puts "Exit code: #{$?}" + out = '' + ignore_interrupts do + wr.close + out << rd.read until rd.eof? + end + unless $?.success? puts out raise end diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 326d8ed513..498029d2ff 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -2,13 +2,6 @@ require 'beer_events' require 'formula' require 'set' -def ignore_interrupts - std_trap = trap("INT") {} - yield -ensure - trap("INT", std_trap) -end - class FormulaInstaller @@attempted = Set.new diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 0f94cce6eb..e30512ff91 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -150,3 +150,10 @@ def inreplace path, before, after f.reopen(path, 'w').write(o) f.close end + +def ignore_interrupts + std_trap = trap("INT") {} + yield +ensure + trap("INT", std_trap) +end