module Mixlib::ShellOut::Windows::Utils

def self.executable?(path)

def self.executable?(path)
  File.executable?(path) && !File.directory?(path)
end

def self.find_executable(path)

for a binary there.
The OS will search through valid the extensions and look
Windows has a different notion of what "executable" means
def self.find_executable(path)
  return path if executable? path
  pathext.each do |ext|
    exe = "#{path}#{ext}"
    return exe if executable? exe
  end
  return nil
end

def self.pathext

def self.pathext
  @pathext ||= ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') + [''] : ['']
end

def self.should_run_under_cmd?(command)

https://github.com/ruby/ruby/blob/9073db5cb1d3173aff62be5b48d00f0fb2890991/win32/win32.c#L1437
This parser is based on

this method should return true.
If there are special characters parsable by cmd.exe (such as file redirection), then
api: semi-private
def self.should_run_under_cmd?(command)
  return true if command =~ /^@/
  quote = nil
  env = false
  env_first_char = false
  command.dup.each_char do |c|
    case c
    when "'", '"'
      if (!quote)
        quote = c
      elsif quote == c
        quote = nil
      end
      next
    when '>', '<', '|', '&', "\n"
      return true unless quote
    when '%'
      return true if env
      env = env_first_char = true
      next
    else
      next unless env
      if env_first_char
        env_first_char = false
        env = false and next if c !~ /[A-Za-z_]/
      end
      env = false if c !~ /[A-Za-z1-9_]/
    end
  end
  return false
end

def self.which(cmd)

FIXME: it is not working
which() mimicks the Unix which command
def self.which(cmd)
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    exe = find_executable("#{path}/#{cmd}")
    return exe if exe
  end
  return nil
end