Set
the default RubyGems API host.
Calls the associated block with the name of every file and directory listed as arguments, then recursively on their subdirectories, and so on.
Returns an enumerator if no block is given.
See the Find
module documentation for an example.
Calls the associated block with the name of every file and directory listed as arguments, then recursively on their subdirectories, and so on.
Returns an enumerator if no block is given.
See the Find
module documentation for an example.
Executes command with expanding variables, and returns the exit status like as Kernel#system
. If werror is true and the error output is not empty, returns false
. The output will logged.
Merges the given URI
strings str
per RFC 2396.
Each string in str
is converted to an RFC3986 URI before being merged.
Examples:
URI.join("http://example.com/","main.rbx") # => #<URI::HTTP http://example.com/main.rbx> URI.join('http://example.com', 'foo') # => #<URI::HTTP http://example.com/foo> URI.join('http://example.com', '/foo', '/bar') # => #<URI::HTTP http://example.com/bar> URI.join('http://example.com', '/foo', 'bar') # => #<URI::HTTP http://example.com/bar> URI.join('http://example.com', '/foo/', 'bar') # => #<URI::HTTP http://example.com/foo/bar>
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
.
The method does not wait for child processes to exit, so the caller must do so.
With no block given, returns a 2-element array containing:
The stdout
stream of the last child process.
An array of the wait threads for all of the child processes.
Example:
last_stdout, wait_threads = Open3.pipeline_r('ls', 'grep R') # => [#<IO:fd 5>, [#<Process::Waiter:0x000055e8de2f9898 dead>, #<Process::Waiter:0x000055e8de2f94b0 sleep>]] puts last_stdout.read wait_threads.each do |wait_thread| wait_thread.join end
Output:
Rakefile README.md
With a block given, calls the block with the stdout
stream of the last child process, and an array of the wait processes:
Open3.pipeline_r('ls', 'grep R') do |last_stdout, wait_threads| puts last_stdout.read wait_threads.each do |wait_thread| wait_thread.join end end
Output:
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.
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
.
The method does not wait for child processes to exit, so the caller must do so.
With no block given, returns a 2-element array containing:
The stdout
stream of the last child process.
An array of the wait threads for all of the child processes.
Example:
last_stdout, wait_threads = Open3.pipeline_r('ls', 'grep R') # => [#<IO:fd 5>, [#<Process::Waiter:0x000055e8de2f9898 dead>, #<Process::Waiter:0x000055e8de2f94b0 sleep>]] puts last_stdout.read wait_threads.each do |wait_thread| wait_thread.join end
Output:
Rakefile README.md
With a block given, calls the block with the stdout
stream of the last child process, and an array of the wait processes:
Open3.pipeline_r('ls', 'grep R') do |last_stdout, wait_threads| puts last_stdout.read wait_threads.each do |wait_thread| wait_thread.join end end
Output:
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.
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 first child, pipes the caller’s stdout
to the child’s stdin
.
The method does not wait for child processes to exit, so the caller must do so.
With no block given, returns a 2-element array containing:
The stdin
stream of the first child process.
An array of the wait threads for all of the child processes.
Example:
first_stdin, wait_threads = Open3.pipeline_w('sort', 'cat -n') # => [#<IO:fd 7>, [#<Process::Waiter:0x000055e8de928278 run>, #<Process::Waiter:0x000055e8de923e80 run>]] first_stdin.puts("foo\nbar\nbaz") first_stdin.close # Send EOF to sort. wait_threads.each do |wait_thread| wait_thread.join end
Output:
1 bar 2 baz 3 foo
With a block given, calls the block with the stdin
stream of the first child process, and an array of the wait processes:
Open3.pipeline_w('sort', 'cat -n') do |first_stdin, wait_threads| first_stdin.puts("foo\nbar\nbaz") first_stdin.close # Send EOF to sort. wait_threads.each do |wait_thread| wait_thread.join end end
Output:
1 bar 2 baz 3 foo
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.
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 first child, pipes the caller’s stdout
to the child’s stdin
.
The method does not wait for child processes to exit, so the caller must do so.
With no block given, returns a 2-element array containing:
The stdin
stream of the first child process.
An array of the wait threads for all of the child processes.
Example:
first_stdin, wait_threads = Open3.pipeline_w('sort', 'cat -n') # => [#<IO:fd 7>, [#<Process::Waiter:0x000055e8de928278 run>, #<Process::Waiter:0x000055e8de923e80 run>]] first_stdin.puts("foo\nbar\nbaz") first_stdin.close # Send EOF to sort. wait_threads.each do |wait_thread| wait_thread.join end
Output:
1 bar 2 baz 3 foo
With a block given, calls the block with the stdin
stream of the first child process, and an array of the wait processes:
Open3.pipeline_w('sort', 'cat -n') do |first_stdin, wait_threads| first_stdin.puts("foo\nbar\nbaz") first_stdin.close # Send EOF to sort. wait_threads.each do |wait_thread| wait_thread.join end end
Output:
1 bar 2 baz 3 foo
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.
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:
wait_threads = Open3.pipeline('ls', 'grep R') # => [#<Process::Status: pid 2139200 exit 0>, #<Process::Status: pid 2139202 exit 0>]
Output:
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.
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:
wait_threads = Open3.pipeline('ls', 'grep R') # => [#<Process::Status: pid 2139200 exit 0>, #<Process::Status: pid 2139202 exit 0>]
Output:
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.
Compatibility methods for Ruby 3.2, we can remove this after dropping to support Ruby 3.2
Builds a command line string from an argument list, array
.
All elements are joined into a single string with fields separated by a space, where each element is escaped for the Bourne shell and stringified using to_s
. See also Shellwords.shellescape
.
ary = ["There's", "a", "time", "and", "place", "for", "everything"] argv = Shellwords.join(ary) argv #=> "There\\'s a time and place for everything"
Array#shelljoin
is a shortcut for this function.
ary = ["Don't", "rock", "the", "boat"] argv = ary.shelljoin argv #=> "Don\\'t rock the boat"
You can also mix non-string objects in the elements as allowed in Array#join
.
output = `#{['ps', '-p', $$].shelljoin}`
Builds a command line string from an argument list, array
.
All elements are joined into a single string with fields separated by a space, where each element is escaped for the Bourne shell and stringified using to_s
. See also Shellwords.shellescape
.
ary = ["There's", "a", "time", "and", "place", "for", "everything"] argv = Shellwords.join(ary) argv #=> "There\\'s a time and place for everything"
Array#shelljoin
is a shortcut for this function.
ary = ["Don't", "rock", "the", "boat"] argv = ary.shelljoin argv #=> "Don\\'t rock the boat"
You can also mix non-string objects in the elements as allowed in Array#join
.
output = `#{['ps', '-p', $$].shelljoin}`