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, stdin: "", timeout: MiniMagick.timeout) ⇒ Object
- #run(command, errors: MiniMagick.errors, warnings: MiniMagick.warnings, **options) ⇒ Object
Instance Method Details
#execute(command, stdin: "", timeout: MiniMagick.timeout) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/mini_magick/shell.rb', line 29 def execute(command, stdin: "", timeout: MiniMagick.timeout) stdout, stderr, status = log(command.join(" ")) do Open3.capture3({ "MAGICK_TIME_LIMIT" => timeout&.to_s }, *command, stdin_data: stdin) end [stdout, stderr, status&.exitstatus] rescue Errno::ENOENT, IOError ["", "executable not found: \"#{command.first}\"", 127] end |
#run(command, errors: MiniMagick.errors, warnings: MiniMagick.warnings, **options) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mini_magick/shell.rb', line 13 def run(command, errors: MiniMagick.errors, warnings: MiniMagick.warnings, **) stdout, stderr, status = execute(command, **) if status != 0 if stderr.include?("time limit exceeded") fail MiniMagick::TimeoutError, "`#{command.join(" ")}` has timed out" elsif errors fail MiniMagick::Error, "`#{command.join(" ")}` failed with status: #{status.inspect} and error:\n#{stderr}" end end $stderr.print(stderr) if warnings [stdout, stderr, status] end |