End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Open3#popen2e
popen2e(*cmd, &block)
lib/open3.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.2.0/lib/open3.rb, line 196
def popen2e(*cmd, &block)
if Hash === cmd.last
opts = cmd.pop.dup
else
opts = {}
end
in_r, in_w = IO.pipe
opts[:in] = in_r
in_w.sync = true
out_r, out_w = IO.pipe
opts[[:out, :err]] = out_w
popen_run(cmd, opts, [in_r, out_w], [in_w, out_r], &block)
ensure
if block
in_r.close
in_w.close
out_r.close
out_w.close
end
end
Open3.popen2e is similar to Open3.popen3 except that it merges the standard output stream and the standard error stream.
Block form:
Open3.popen2e([env,] cmd... [, opts]) {|stdin, stdout_and_stderr, wait_thr|
pid = wait_thr.pid # pid of the started process.
...
exit_status = wait_thr.value # Process::Status object returned.
}
Non-block form:
stdin, stdout_and_stderr, wait_thr = Open3.popen2e([env,] cmd... [, opts]) ... stdin.close # stdin and stdout_and_stderr should be closed explicitly in this form. stdout_and_stderr.close
See Process.spawn for the optional hash arguments env and opts.
Example:
# check gcc warnings
source = "foo.c"
Open3.popen2e("gcc", "-Wall", source) {|i,oe,t|
oe.each {|line|
if /warning/ =~ line
...
end
}
}