Read if no block is passed to Utils.popen_read

This commit is contained in:
Jack Nagel 2014-07-11 15:51:19 -05:00
parent 677cd51977
commit 5c24b7330b
3 changed files with 8 additions and 4 deletions

View File

@ -231,13 +231,13 @@ module OS
def mdfind(*ids)
return [] unless OS.mac?
(@mdfind ||= {}).fetch(ids) do
@mdfind[ids] = Utils.popen_read("/usr/bin/mdfind", mdfind_query(*ids), &:read).split("\n")
@mdfind[ids] = Utils.popen_read("/usr/bin/mdfind", mdfind_query(*ids)).split("\n")
end
end
def pkgutil_info(id)
(@pkginfo ||= {}).fetch(id) do |key|
@pkginfo[key] = Utils.popen_read("/usr/sbin/pkgutil", "--pkg-info", key, &:read).strip
@pkginfo[key] = Utils.popen_read("/usr/sbin/pkgutil", "--pkg-info", key).strip
end
end

View File

@ -57,7 +57,7 @@ module OS
def version_from_mdls(path)
version = Utils.popen_read(
"/usr/bin/mdls", "-raw", "-nullMarker", "", "-name", "kMDItemVersion", path.to_s, &:read
"/usr/bin/mdls", "-raw", "-nullMarker", "", "-name", "kMDItemVersion", path.to_s
).strip
version unless version.empty?
end

View File

@ -10,7 +10,11 @@ module Utils
def self.popen(args, mode)
IO.popen("-", mode) do |pipe|
if pipe
if block_given?
yield pipe
else
return pipe.read
end
else
STDERR.reopen("/dev/null", "w")
exec(*args)