Class: SubshellCommand::CombinedOutputStreamsExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/subshell_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command_object, result) ⇒ CombinedOutputStreamsExecutor

Returns a new instance of CombinedOutputStreamsExecutor.



84
85
86
87
# File 'lib/subshell_command.rb', line 84

def initialize(command_object, result)
  @command_object = command_object
  @result = result
end

Instance Attribute Details

#command_objectObject (readonly)

Returns the value of attribute command_object.



82
83
84
# File 'lib/subshell_command.rb', line 82

def command_object
  @command_object
end

#resultObject (readonly)

Returns the value of attribute result.



82
83
84
# File 'lib/subshell_command.rb', line 82

def result
  @result
end

Instance Method Details

#executeObject



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/subshell_command.rb', line 89

def execute
  Open3.popen2e(
    command_object.env_hash,
    command_object.command_string,
    chdir: command_object.current_directory,
  ) do |stdin, output_streams, wait_thr|
    exit_status = wait_thr.value
    output_value = output_streams.read
    result.stdout_value = output_value
    result.stderr_value = output_value
    result.success = exit_status.success?
  end
end