Method: File.which
- Defined in:
- lib/common/ext/file.rb
.which(cmd) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/common/ext/file.rb', line 101 def self.which(cmd) return "" if not 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}") if File.executable?(exe) && !File.directory?(exe) return File.dirname(exe.gsub(/[\\]/,'/')) end } end return "" end |