lib/aruba/processes/spawn_process.rb in aruba-0.8.1 vs lib/aruba/processes/spawn_process.rb in aruba-0.9.0.pre

- old
+ new

@@ -1,10 +1,12 @@ require 'childprocess' require 'tempfile' require 'shellwords' + require 'aruba/errors' require 'aruba/processes/basic_process' +require 'aruba/platform' module Aruba module Processes class SpawnProcess < BasicProcess # Use as default launcher @@ -23,11 +25,11 @@ # @params [Integer] io_wait # The timeout until we expect the io to be finished # # @params [String] working_directory # The directory where the command will be executed - def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV.to_hash, main_class = nil) + def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV.to_hash.dup, main_class = nil) super @exit_timeout = exit_timeout @io_wait = io_wait @process = nil @@ -41,15 +43,19 @@ # Run code for process which was started # # rubocop:disable Metrics/MethodLength # rubocop:disable Metrics/CyclomaticComplexity def run! + # gather fully qualified path + cmd = which(command) # rubocop:disable Metrics/LineLength - fail LaunchError, %(Command "#{command}" not found in PATH-variable "#{environment['PATH']}".) unless which(command, environment['PATH']) + fail LaunchError, %(Command "#{command}" not found in PATH-variable "#{environment['PATH']}".) if cmd.nil? # rubocop:enable Metrics/LineLength - @process = ChildProcess.build(which(command, environment['PATH']), *arguments) + cmd = Aruba.platform.command_string.new(cmd) + + @process = ChildProcess.build(*[cmd.to_a, arguments].flatten) @out = Tempfile.new("aruba-out") @err = Tempfile.new("aruba-err") @exit_status = nil @duplex = true @@ -63,10 +69,10 @@ @process.environment.update(environment) begin @process.start rescue ChildProcess::LaunchError => e - raise LaunchError, e.message + raise LaunchError, "It tried to start #{cmd}. " + e.message end after_run yield self if block_given?