CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/msf/util/helper.rb
Views: 11780
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