code: def which(program, add_win_suffixes=True):
      
      def is_exe(fpath):
          """Determine if program exists and is executable."""
          return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
  
      fpath, fname = os.path.split(program)
      if add_win_suffixes and platform.system().lower() == 'windows' and not (
              fname.endswith('.exe') or fname.endswith('.cmd')):
          fnames = [fname + '.exe', fname + '.cmd']
      else:
          fnames = [fname]
  
      for i in fnames:
          if fpath:
              exe_file = os.path.join(fpath, i)
              if is_exe(exe_file):
                  return exe_file
          else:
              for path in os.environ['PATH'].split(os.pathsep):
                  exe_file = os.path.join(path, i)
                  if is_exe(exe_file):
                      return exe_file
  
      return None
docs: Mimic 'which' command behavior.
  
      Adapted from https://stackoverflow.com/a/377028