blob: 76e67b3a98cf604e83c1197c2f4a6f003fdd8888 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
module Utils
def self.popen_read(*args, &block)
popen(args, "rb", &block)
end
def self.popen_read_text(*args, &block)
popen(args, "r", &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
if block_given?
yield pipe
else
return pipe.read
end
else
$stderr.reopen("/dev/null", "w")
exec(*args)
end
end
end
end
|