module FeduxOrg module Stdlib module Command module Which # Search for command # @param [String] cmd # name of command or path to command (will be reduced to basename and then searched in PATH) # # @param [Array,String] paths # a string containing paths separated by "File::PATH_SEPARATOR" or an array of paths # # @param [Array,String] pathexts # a string containing pathexts separated by ";" or an array of pathexts # # @return [String] # path to command def which(cmd, paths=ENV['PATH'].split(File::PATH_SEPARATOR), pathexts=ENV['PATHEXT'].to_s.split( /;/ ) ) return nil if cmd.blank? cmd = File.basename( cmd ) pathexts = [''] if pathexts.blank? Array( paths ).each do |path| Array( pathexts ).each do |ext| exe = File.join(path, "#{cmd}#{ext.to_s}") return exe if File.executable? exe end end nil end end end end end