Class: MiniMagick::Shell
- Inherits:
-
Object
- Object
- MiniMagick::Shell
- 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
- #execute(command) ⇒ Object
-
#initialize(whiny = true) ⇒ Shell
constructor
A new instance of Shell.
- #run(command) ⇒ Object
Constructor Details
#initialize(whiny = true) ⇒ Shell
Returns a new instance of Shell.
15 16 17 |
# File 'lib/mini_magick/shell.rb', line 15 def initialize(whiny = true) @whiny = whiny end |
Instance Method Details
#execute(command) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/mini_magick/shell.rb', line 34 def execute(command) stdout, stderr, status = MiniMagick.logger.debug(command.join(" ")) do Timeout.timeout(MiniMagick.timeout) do Open3.capture3(*command) end end [stdout, stderr, status.exitstatus] rescue Errno::ENOENT ["", "executable not found: \"#{command.first}\"", 127] end |
#run(command) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mini_magick/shell.rb', line 19 def run(command) stdout, stderr, code = execute(command) case code when 1 fail MiniMagick::Error, "`#{command.join(" ")}` failed with error:\n#{stderr}" when 127 fail MiniMagick::Error, stderr end if @whiny $stderr.print(stderr) stdout end |