Skip to content

Commit

Permalink
popen: Add an options argument
Browse files Browse the repository at this point in the history
Useful for selectively enabling or silencing stderr, for example.
popen_read("foo", err: :err)
  • Loading branch information
sjackman committed Sep 20, 2017
1 parent 5d888c0 commit 8bf2847
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions Library/Homebrew/utils/popen.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
module Utils
def self.popen_read(*args, &block)
popen(args, "rb", &block)
def self.popen_read(*args, **options, &block)
popen(args, "rb", options, &block)
end

def self.popen_write(*args, &block)
popen(args, "wb", &block)
def self.popen_write(*args, **options, &block)
popen(args, "wb", options, &block)
end

def self.popen(args, mode)
def self.popen(args, mode, options = {})
IO.popen("-", mode) do |pipe|
if pipe
return pipe.read unless block_given?
yield pipe
else
$stderr.reopen("/dev/null", "w")
exec(*args)
options[:err] ||= :close
exec(*args, options)
end
end
end
Expand Down

0 comments on commit 8bf2847

Please sign in to comment.