blob: 86595342a4de75f312d1d585c2692e29067d0be0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
module EnvUtil
def find_executable(cmd, *args)
exts = RbConfig::CONFIG["EXECUTABLE_EXTS"].split | [RbConfig::CONFIG["EXEEXT"]]
ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
next if path.empty?
path = File.join(path, cmd)
exts.each do |ext|
cmdline = [path + ext, *args]
begin
return cmdline if yield(IO.popen(cmdline, "r", err: [:child, :out], &:read))
rescue
next
end
end
end
nil
end
module_function :find_executable
end
|