Add popen wrapper that does not invoke the shell
This commit is contained in:
parent
84372e570e
commit
ad27b21cd1
@ -5,4 +5,10 @@ class UtilTests < Homebrew::TestCase
|
||||
# Issue #217 put columns with new results fails.
|
||||
assert_silent { puts_columns [] }
|
||||
end
|
||||
|
||||
def test_popen_read
|
||||
out = Utils.popen_read("/bin/sh", "-c", "echo success", &:read).chomp
|
||||
assert_equal "success", out
|
||||
assert_predicate $?, :success?
|
||||
end
|
||||
end
|
||||
|
||||
@ -3,6 +3,7 @@ require 'exceptions'
|
||||
require 'os/mac'
|
||||
require 'utils/json'
|
||||
require 'utils/inreplace'
|
||||
require 'utils/popen'
|
||||
require 'open-uri'
|
||||
|
||||
class Tty
|
||||
|
||||
20
Library/Homebrew/utils/popen.rb
Normal file
20
Library/Homebrew/utils/popen.rb
Normal file
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user