Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

Open3.capture2e

capture2e(*cmd)

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")
See also #capture2e .capture2 .capture3 .pipeline also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1