module ImageOptimizer::Shell::ClassMethods

Public Instance Methods

run_command(command) click to toggle source
# File lib/image_optimizer/shell.rb, line 30
def run_command(command)
  `#{command}`
end
which(cmd) click to toggle source

Cross-platform way of finding an executable in the $PATH.

# File lib/image_optimizer/shell.rb, line 19
def 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
    end
  end
  nil
end