aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/utils/popen.rb
diff options
context:
space:
mode:
Diffstat (limited to 'Library/Homebrew/utils/popen.rb')
-rw-r--r--Library/Homebrew/utils/popen.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/Library/Homebrew/utils/popen.rb b/Library/Homebrew/utils/popen.rb
new file mode 100644
index 000000000..83f140163
--- /dev/null
+++ b/Library/Homebrew/utils/popen.rb
@@ -0,0 +1,20 @@
+module Utils
+ def self.popen_read(*args, &block)
+ popen(args, "rb", &block)
+ end
+
+ def self.popen_write(*args, &block)
+ popen(args, "wb", &block)
+ end
+
+ def self.popen(args, mode)
+ IO.popen("-", mode) do |pipe|
+ if pipe
+ yield pipe
+ else
+ STDERR.reopen("/dev/null", "w")
+ exec(*args)
+ end
+ end
+ end
+end