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-09-19 10:18:04 -07:00
|
|
|
exec(*args, options)
|
2014-07-05 13:50:54 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|