Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

class method

Open3.pipeline

Open3.pipeline([env, ] *cmds, options = {}) → array_of_statuses

Basically a wrapper for Process.spawn that:

  • Creates a child process for each of the given cmds by calling Process.spawn.

  • Pipes the stdout from each child to the stdin of the next child, or, for the last child, to the caller’s stdout.

  • Waits for the child processes to exit.

  • Returns an array of Process::Status objects (one for each child).

Example:

Example
wait_threads = Open3.pipeline('ls', 'grep R')
# => [#<Process::Status: pid 2139200 exit 0>, #<Process::Status: pid 2139202 exit 0>]

Output:

Example
Rakefile
README.md

Like Process.spawn, this method has potential security vulnerabilities if called with untrusted input; see Command Injection.

If the first argument is a hash, it becomes leading argument env in each call to Process.spawn; see Execution Environment.

If the last argument is a hash, it becomes trailing argument options in each call to Process.spawn‘ see Execution Options.

Each remaining argument in cmds is one of:

  • A command_line: a string that begins with a shell reserved word or special built-in, or contains one or more metacharacters.

  • An exe_path: the string path to an executable to be called.

  • An array containing a command_line or an exe_path, along with zero or more string arguments for the command.

See Argument command_line or exe_path.

See also #pipeline .capture3 .pipeline_r .capture2e also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0