Class: MiniMagick::Shell

Inherits:
Object
  • Object
show all
Defined in:
lib/mini_magick/shell.rb

Overview

Sends commands to the shell (more precisely, it sends commands directly to the operating system).

Instance Method Summary collapse

Instance Method Details

#execute(command, options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/mini_magick/shell.rb', line 25

def execute(command, options = {})
  stdout, stderr, status =
    log(command.join(" ")) do
      send("execute_#{MiniMagick.shell_api.tr("-", "_")}", command, options)
    end

  [stdout, stderr, status.exitstatus]
rescue Errno::ENOENT, IOError
  ["", "executable not found: \"#{command.first}\"", 127]
end

#run(command, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/mini_magick/shell.rb', line 13

def run(command, options = {})
  stdout, stderr, status = execute(command, stdin: options[:stdin])

  if status != 0 && options.fetch(:whiny, MiniMagick.whiny)
    fail MiniMagick::Error, "`#{command.join(" ")}` failed with status: #{status} and error:\n#{stderr}"
  end

  $stderr.print(stderr) unless options[:stderr] == false

  [stdout, stderr, status]
end