On this page
Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
Open3
Module Open3 supports creating child processes with access to their $stdin, $stdout, and $stderr streams.
What’s Here
Each of these methods executes a given command in a new process or subshell, or multiple commands in new processes and/or subshells:
-
Each of these methods executes a single command in a process or subshell, accepts a string for input to $stdin, and returns string output from $stdout, $stderr, or both:
-
Open3.capture2: Executes the command; returns the string from $stdout. -
Open3.capture2e: Executes the command; returns the string from merged $stdout and $stderr. -
Open3.capture3: Executes the command; returns strings from $stdout and $stderr.
-
-
Each of these methods executes a single command in a process or subshell, and returns pipes for $stdin, $stdout, and/or $stderr:
-
Open3.popen2: Executes the command; returns pipes for $stdin and $stdout. -
Open3.popen2e: Executes the command; returns pipes for $stdin and merged $stdout and $stderr. -
Open3.popen3: Executes the command; returns pipes for $stdin, $stdout, and $stderr.
-
-
Each of these methods executes one or more commands in processes and/or subshells, returns pipes for the first $stdin, the last $stdout, or both:
-
Open3.pipeline_r: Returns a pipe for the last $stdout. -
Open3.pipeline_rw: Returns pipes for the first $stdin and the last $stdout. -
Open3.pipeline_w: Returns a pipe for the first $stdin. -
Open3.pipeline_start: Does not wait for processes to complete. -
Open3.pipeline: Waits for processes to complete.
-
Each of the methods above accepts:
-
An optional hash of environment variable names and values; see Execution Environment.
-
A required string argument that is a
command_lineorexe_path; see Argument command_line or exe_path. -
An optional hash of execution options; see Execution Options.