Cross-platform way of finding an executable in the $PATH.
 Taken from
 http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby

   which('ruby') #=> /usr/bin/ruby
336218
def which(cmd)
      exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
      ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
        exts.each { |ext|
          exe = "#{path}/#{cmd}#{ext}"
          return exe if File.executable? exe
        }
      end
      return nil
    end
1207337
def is_exe(fpath):
    
    return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
67306
def find_file(name)
      @load_path.each do |dir|
        file_path = File.join(dir, "#{name}.rb")
        return file_path if File.exist? file_path
      end
      raise("Module #{name} not found")
    end
495488
def executable(self):
        
        return util.find_executable(self.BINS[0], os.path.join("bin", self.BINS[0]) )
688771
def find_program(basename):
    
    names = [basename]
    if os.name == 'nt':
        # Windows platforms
        extensions = ('.exe', '.bat', '.cmd')
        if not basename.endswith(extensions):
            names = [basename+ext for ext in extensions]+[basename]
    for name in names:
        path = is_program_installed(name)
        if path:
            return path
1214380
def find_protoc(path=os.environ['PATH']):
    '''
    
    '''
    protoc_filename = 'protoc'

    bin_search_paths = path.split(':') or []
    for search_path in bin_search_paths:
        bin_path = os.path.join(search_path, protoc_filename)
        if os.path.isfile(bin_path) and os.access(bin_path, os.X_OK):
            return bin_path

    raise ProtocNotFound("Protobuf compiler not found")
445159
def file_exists?(paths, file)
      paths.any? do |path|
        Find.find(path)
            .map { |path_file| Shellwords.escape(path_file) }
            .include?(file)
      end
    end
1018865
def find_binary_in_path(filename):
    
    if 'PATH' not in os.environ:
        return None
    for directory in os.environ['PATH'].split(get_variable_separator()):
        binary = os.path.abspath(os.path.join(directory, filename))
        if os.path.isfile(binary) and os.access(binary, os.X_OK):
            return binary
    return None
1042171
def islink(path):
    
    if platform.system() == "Windows":
        if sys.version_info[:2] < (3, 5):
            try:
                # pylint: disable=undefined-variable
                attrs = ctypes.windll.kernel32.GetFileAttributesW(unicode(path))  # noqa
                assert attrs != -1
                return bool(attrs & FILE_ATTRIBUTE_REPARSE_POINT)
            except (AttributeError, AssertionError):
                return False
        try:
            st = os.lstat(path)  # pylint: disable=invalid-name
        except (OSError, AttributeError):
            return False
        # pylint: disable=no-member
        return stat.S_ISLNK(st.st_mode) or st.st_file_attributes & stat.FILE_ATTRIBUTE_REPARSE_POINT
    return os.path.islink(path)
1134388
def _findSwiplDar():
    

    # If the exec is in path
    (path, swiHome) = _findSwiplFromExec()
    if path is not None:
        return (path, swiHome)

    # If it is not, use  find_library
    path = _findSwiplPathFromFindLib()
    if path is not None:
        return (path, swiHome)

    # Last guess, searching for the file
    paths = ['.', './lib', '/usr/lib/', '/usr/local/lib', '/opt/local/lib']
    names = ['libswipl.dylib', 'libpl.dylib']

    for name in names:
        for path in paths:
            path = os.path.join(path, name)
            if os.path.exists(path):
                return (path, None)

    return (None, None)
317029
def which(exe_name):
    
    def is_exe(file_path_name):
        return os.path.isfile(file_path_name) and os.access(file_path_name, os.X_OK)

    is_platform_windows = (platform.system() == 'Windows')

    fpath, _fname = os.path.split(exe_name)
    if fpath:
        if is_exe(exe_name):
            return exe_name
    else:
        for path in os.environ['PATH'].split(os.pathsep):
            exe_file_path_name = os.path.join(path, exe_name)
            if is_exe(exe_file_path_name):
                return exe_file_path_name

            if is_platform_windows:
                windows_exe_file_path_name = '%s.exe' % exe_file_path_name
                if is_exe(windows_exe_file_path_name):
                    return windows_exe_file_path_name

                windows_com_file_path_name = '%s.exe' % exe_file_path_name
                if is_exe(windows_com_file_path_name):
                    return windows_com_file_path_name

    return None
400624
function findFirefox() {
  if (foundBinary) {
    return foundBinary;
  }

  if (process.platform === 'darwin') {
    var osxExe =  '/Applications/Firefox.app/Contents/MacOS/firefox-bin';
    foundBinary = io.exists(osxExe).then(function(exists) {
      return exists ? osxExe : null;
    });
  } else if (process.platform === 'win32') {
    foundBinary = defaultWindowsLocation();
  } else {
    foundBinary = promise.fulfilled(io.findInPath('firefox'));
  }

  return foundBinary = foundBinary.then(function(found) {
    if (found) {
      return found;
    }
    throw Error('Could not locate Firefox on the current system');
  });
}
417979
def find_executable(name)
      @project.from_directory do
        Find.find("kit") do |path|
          next unless path =~ %r{(.*bin)/#{name}$} && File.executable?(path)
          result = Regexp.last_match[1]

          log.debug("found #{name} executable in #{result}")
          return result
        end
      end

      nil
    end
1041589
def find_executable(name):
    
    for pt in os.environ.get('PATH', '').split(':'):
        candidate = os.path.join(pt, name)
        if os.path.exists(candidate):
            return candidate
448747
def which(cmd, safe=False):
    """"""
    from autopaths.file_path import FilePath
    def is_executable(path):
        return os.path.exists(path) and os.access(path, os.X_OK) and not os.path.isdir(path)
    path, name = os.path.split(cmd)
    if path:
        if is_executable(cmd): return FilePath(cmd)
    else:
        for path in os.environ['PATH'].split(os.pathsep):
            candidate = os.path.join(path, cmd)
            if is_executable(candidate): return FilePath(candidate)
    if not safe: raise Exception('which failed to locate a proper command path "%s"' % cmd)
560405
def isexec(path):
    '''
    
    '''
    return os.path.isfile(path) and os.access(path, os.X_OK)
29014
def which(component, path_str):
    ''''''

    def is_exe(fpath):
        return os.path.exists(fpath) and os.access(fpath, os.X_OK)

    fpath, fname = os.path.split(component)
    if fpath:
        if is_exe(component):
            return component
    else:
        for path in path_str.split(os.pathsep):
            exe_file = os.path.join(path, component)
            if is_exe(exe_file):
                return exe_file