CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/msf/util/helper.rb
Views: 1904
1
# -*- coding: binary -*-
2
3
module Msf
4
module Util
5
class Helper
6
# Cross-platform way of finding an executable in the $PATH.
7
#
8
# which('ruby') #=> /usr/bin/ruby
9
def self.which(cmd)
10
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
11
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
12
exts.each { |ext|
13
exe = File.join(path, "#{cmd}#{ext}")
14
return exe if File.executable?(exe) && !File.directory?(exe)
15
}
16
end
17
return nil
18
end
19
end
20
end
21
end
22
23