class Exedit::Command

A system command checking class

Public Class Methods

which(cmd) click to toggle source

Gets the path to a system command, returns nil if none found

# File lib/exedit/command.rb, line 5
def self.which(cmd)
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']

  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    exts.each do |ext|
      exe = File.join(path, "#{cmd}#{ext}")
      return exe if File.executable?(exe) && !File.directory?(exe)
    end
  end

  nil
end