2014-07-05 13:50:54 -05:00
|
|
|
module Utils
|
2017-09-19 10:18:04 -07:00
|
|
|
def self.popen_read(*args, **options, &block)
|
|
|
|
popen(args, "rb", options, &block)
|
2014-07-05 13:50:54 -05:00
|
|
|
end
|
|
|
|
|
2017-09-19 10:18:04 -07:00
|
|
|
def self.popen_write(*args, **options, &block)
|
|
|
|
popen(args, "wb", options, &block)
|
2014-07-05 13:50:54 -05:00
|
|
|
end
|
|
|
|
|
2017-09-19 10:18:04 -07:00
|
|
|
def self.popen(args, mode, options = {})
|
2014-07-05 13:50:54 -05:00
|
|
|
IO.popen("-", mode) do |pipe|
|
|
|
|
if pipe
|
2016-09-23 22:02:23 +02:00
|
|
|
return pipe.read unless block_given?
|
|
|
|
yield pipe
|
2014-07-05 13:50:54 -05:00
|
|
|
else
|
2017-09-20 11:58:52 -07:00
|
|
|
options[:err] ||= :close unless ENV["HOMEBREW_STDERR"]
|
2017-12-01 15:00:27 -08:00
|
|
|
begin
|
|
|
|
exec(*args, options)
|
|
|
|
rescue Errno::ENOENT
|
|
|
|
$stderr.puts "brew: command not found: #{args[0]}" unless options[:err] == :close
|
|
|
|
exit! 127
|
|
|
|
rescue SystemCallError
|
|
|
|
$stderr.puts "brew: exec failed: #{args[0]}" unless options[:err] == :close
|
|
|
|
exit! 1
|
|
|
|
end
|
2014-07-05 13:50:54 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|