Sha256: ad343e3ebe5cfc242c64c1cb7bd6d1147fb7c399e6ea1ee08a113fbbd58b6a69
Contents?: true
Size: 1.5 KB
Versions: 1
Compression:
Stored size: 1.5 KB
Contents
# frozen_string_literal: true require 'childprocess' require_relative '../errors' module Lino module Executors class Childprocess def execute(command_line, opts = {}) process = ::ChildProcess.build(*command_line.array) set_output_streams(process, opts) set_working_directory(process, command_line.working_directory) set_environment(process, command_line.environment_variables) start_process(process, opts) exit_code = process.wait return if exit_code.zero? raise Lino::Errors::ExecutionError.new( command_line.string, exit_code ) end def ==(other) self.class == other.class end alias eql? == def hash self.class.hash end private def start_process(process, opts) process.duplex = true if opts[:stdin] process.start process.io.stdin.write(opts[:stdin]) if opts[:stdin] end def set_output_streams(process, opts) process.io.inherit! process.io.stdout = opts[:stdout] if opts[:stdout] process.io.stderr = opts[:stderr] if opts[:stderr] end def set_working_directory(process, working_directory) process.cwd = working_directory end def set_environment(process, environment_variables) environment_variables.each do |environment_variable| process.environment[environment_variable.name] = environment_variable.value end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
lino-3.2.0.pre.7 | lib/lino/executors/childprocess.rb |