2017-07-17 07:58:20 +00:00
|
|
|
# -*- coding: binary -*-
|
|
|
|
|
|
|
|
module Msf
|
|
|
|
module Util
|
|
|
|
class Helper
|
|
|
|
# Cross-platform way of finding an executable in the $PATH.
|
|
|
|
#
|
|
|
|
# which('ruby') #=> /usr/bin/ruby
|
|
|
|
def self.which(cmd)
|
|
|
|
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
|
|
|
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
|
|
|
exts.each { |ext|
|
|
|
|
exe = File.join(path, "#{cmd}#{ext}")
|
|
|
|
return exe if File.executable?(exe) && !File.directory?(exe)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
end
|
2017-07-17 08:10:12 +00:00
|
|
|
end
|
|
|
|
end
|