Sha256: 5e57ad7eb918258bfd78ce393e2cbfb80e068d3a8a707efd62d6b707a12815a2

Contents?: true

Size: 824 Bytes

Versions: 10

Compression:

Stored size: 824 Bytes

Contents

require 'open3'
module Riiif
  # Runs shell commands under benchmark and saves the output
  class CommandRunner
    include Open3
    include ActiveSupport::Benchmarkable
    delegate :logger, to: :Rails

    # TODO: this is being loaded into memory.  We could make this a stream.
    # @return [String] all the image data
    def execute(command)
      out = nil
      benchmark("Riiif executed #{command}") do
        stdin, stdout, stderr, wait_thr = popen3(command)
        stdin.close
        stdout.binmode
        out = stdout.read
        stdout.close
        err = stderr.read
        stderr.close
        raise ConversionError, "Unable to execute command \"#{command}\"\n#{err}" unless wait_thr.value.success?
      end
      out
    end

    def self.execute(command)
      new.execute(command)
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
riiif-2.6.0 app/services/riiif/command_runner.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/riiif-2.5.0/app/services/riiif/command_runner.rb
riiif-2.5.0 app/services/riiif/command_runner.rb
riiif-2.4.0 app/services/riiif/command_runner.rb
riiif-2.3.0 app/services/riiif/command_runner.rb
riiif-2.2.0 app/services/riiif/command_runner.rb
riiif-2.1.0 app/services/riiif/command_runner.rb
riiif-2.0.0 app/services/riiif/command_runner.rb
riiif-2.0.0.beta2 app/services/riiif/command_runner.rb
riiif-2.0.0.beta1 app/services/riiif/command_runner.rb