Sha256: 2c8c571ea778bfe8d072f27b554ac96b62e74a81d145eac67ef00bc56c8ea7bc
Contents?: true
Size: 935 Bytes
Versions: 2
Compression:
Stored size: 935 Bytes
Contents
# frozen_string_literal: true require 'open3' module PdfTools # Send commands to the shell class Shell def run(command, **options) stdout, stderr, status = execute(command) if status != 0 raise PdfTools::Error, "Command `#{command.join(' ')}` failed!\n Error: #{stderr}" end $stderr.print(stderr) unless options[:stderr] == false [stdout, stderr, status] end def execute(command) stdout, stderr, status = Open3.popen3(*command) do |stdin, stdout, stderr, wait_thr| [stdin, stdout, stderr].each(&:binmode) stdout_reader = Thread.new { stdout.read } stderr_reader = Thread.new { stderr.read } [stdout_reader.value, stderr_reader.value, wait_thr.value] end [stdout, stderr, status.exitstatus] rescue Errno::ENOENT, IOError ['', "executable not found: \"#{command.first}\"", 127] end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
pdf_tools-0.1.1 | lib/pdf_tools/shell.rb |
pdf_tools-0.1.0 | lib/pdf_tools/shell.rb |