End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
Open3.capture2e
capture2e(*cmd)
lib/open3.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.2.0/lib/open3.rb, line 389
def capture2e(*cmd)
if Hash === cmd.last
opts = cmd.pop.dup
else
opts = {}
end
stdin_data = opts.delete(:stdin_data)
binmode = opts.delete(:binmode)
popen2e(*cmd, opts) {|i, oe, t|
if binmode
i.binmode
oe.binmode
end
outerr_reader = Thread.new { oe.read }
if stdin_data
begin
if stdin_data.respond_to? :readpartial
IO.copy_stream(stdin_data, i)
else
i.write stdin_data
end
rescue Errno::EPIPE
end
end
i.close
[outerr_reader.value, t.value]
}
end
Open3.capture2e captures the standard output and the standard error of a command.
stdout_and_stderr_str, status = Open3.capture2e([env,] cmd... [, opts])
The arguments env, cmd and opts are passed to Open3.popen3 except opts[:stdin_data] and opts[:binmode]. See Process.spawn.
If opts[:stdin_data] is specified, it is sent to the command’s standard input.
If opts[:binmode] is true, internal pipes are set to binary mode.
Example:
Example
# capture make log make_log, s = Open3.capture2e("make")