lib/departure/command.rb in departure-6.3.0 vs lib/departure/command.rb in departure-6.4.0

- old
+ new

@@ -6,14 +6,15 @@ # Constructor # # @param command_line [String] # @param error_log_path [String] # @param logger [#write_no_newline] - def initialize(command_line, error_log_path, logger) + def initialize(command_line, error_log_path, logger, redirect_stderr) @command_line = command_line @error_log_path = error_log_path @logger = logger + @redirect_stderr = redirect_stderr end # Executes the command returning its status. It also prints its stdout to # the logger and its stderr to the file specified in error_log_path. # @@ -33,11 +34,11 @@ status end private - attr_reader :command_line, :error_log_path, :logger, :status + attr_reader :command_line, :error_log_path, :logger, :status, :redirect_stderr # Runs the command in a separate process, capturing its stdout and # execution status def run_in_process Open3.popen3(full_command) do |_stdin, stdout, _stderr, waith_thr| @@ -54,14 +55,18 @@ end end end # Builds the actual command including stderr redirection to the specified - # log file + # log file or stdout # # @return [String] def full_command - "#{command_line} 2> #{error_log_path}" + if redirect_stderr + "#{command_line} 2> #{error_log_path}" + else + "#{command_line} 2>&1" + end end # Validates the status of the execution # # @raise [NoStatusError] if the spawned process' status can't be retrieved