lib/mini_magick/shell.rb in mini_magick-4.0.2 vs lib/mini_magick/shell.rb in mini_magick-4.0.3
- old
+ new
@@ -1,8 +1,6 @@
require "mini_magick/logger"
-
-require "open3"
require "timeout"
module MiniMagick
##
# Sends commands to the shell (more precisely, it sends commands directly to
@@ -33,16 +31,31 @@
def execute(command)
stdout, stderr, status =
MiniMagick.logger.debug(command.join(" ")) do
Timeout.timeout(MiniMagick.timeout) do
- Open3.capture3(*command)
+ send("execute_#{MiniMagick.shell_api.gsub("-", "_")}", *command)
end
end
[stdout, stderr, status.exitstatus]
- rescue Errno::ENOENT
+ rescue Errno::ENOENT, IOError
["", "executable not found: \"#{command.first}\"", 127]
+ end
+
+ private
+
+ def execute_open3(*command)
+ require "open3"
+ Open3.capture3(*command)
+ end
+
+ def execute_posix_spawn(*command)
+ require "posix-spawn"
+ pid, stdin, stdout, stderr = POSIX::Spawn.popen4(*command)
+ Process.waitpid(pid)
+
+ [stdout.read, stderr.read, $?]
end
end
end