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.
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
.
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
.
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}`
Returns the singleton instance.
Returns the sine of x
in radians.
Domain: (-INFINITY, INFINITY)
.
Range: [-1.0, 1.0]
.
Examples:
sin(-PI) # => -1.2246063538223773e-16 # -0.0000000000000001 sin(-PI/2) # => -1.0 sin(0.0) # => 0.0 sin(PI/2) # => 1.0 sin(PI) # => 1.2246063538223773e-16 # 0.0000000000000001
Returns the arc sine of x
.
Domain: [-1, -1]
.
Range: [-PI/2, PI/2]
.
Examples:
asin(-1.0) # => -1.5707963267948966 # -PI/2 asin(0.0) # => 0.0 asin(1.0) # => 1.5707963267948966 # PI/2
Returns the hyperbolic sine of x
in radians.
Domain: [-INFINITY, INFINITY]
.
Range: [-INFINITY, INFINITY]
.
Examples:
sinh(-INFINITY) # => -Infinity sinh(0.0) # => 0.0 sinh(INFINITY) # => Infinity
Returns the inverse hyperbolic sine of x
.
Domain: [-INFINITY, INFINITY]
.
Range: [-INFINITY, INFINITY]
.
Examples:
asinh(-INFINITY) # => -Infinity asinh(0.0) # => 0.0 asinh(INFINITY) # => Infinity
Returns the value of the gamma function for x
.
Domain: (-INFINITY, INFINITY]
excluding negative integers.
Range: [-INFINITY, INFINITY]
.
Examples:
gamma(-2.5) # => -0.9453087204829431 gamma(-1.5) # => 2.3632718012073513 gamma(-0.5) # => -3.5449077018110375 gamma(0.0) # => Infinity gamma(1.0) # => 1.0 gamma(2.0) # => 1.0 gamma(3.0) # => 2.0 gamma(4.0) # => 6.0 gamma(5.0) # => 24.0
Related: Math.lgamma
.
Returns a 2-element array equivalent to:
[Math.log(Math.gamma(x).abs), Math.gamma(x) < 0 ? -1 : 1]
See logarithmic gamma function.
Domain: (-INFINITY, INFINITY]
.
Range
of first element: (-INFINITY, INFINITY]
.
Second element is -1 or 1.
Examples:
lgamma(-4.0) # => [Infinity, -1] lgamma(-3.0) # => [Infinity, -1] lgamma(-2.0) # => [Infinity, -1] lgamma(-1.0) # => [Infinity, -1] lgamma(0.0) # => [Infinity, 1] lgamma(1.0) # => [0.0, 1] lgamma(2.0) # => [0.0, 1] lgamma(3.0) # => [0.6931471805599436, 1] lgamma(4.0) # => [1.7917594692280545, 1] lgamma(-2.5) # => [-0.05624371649767279, -1] lgamma(-1.5) # => [0.8600470153764797, 1] lgamma(-0.5) # => [1.265512123484647, -1] lgamma(0.5) # => [0.5723649429247004, 1] lgamma(1.5) # => [-0.12078223763524676, 1] lgamma(2.5) # => [0.2846828704729205, 1]
Related: Math.gamma
.
Returns a 2-element array of the current (soft) limit and maximum (hard) limit for the given resource
.
Argument resource
specifies the resource whose limits are to be returned; see Process.setrlimit
.
Each of the returned values cur_limit
and max_limit
is an integer; see Process.setrlimit
.
Example:
Process.getrlimit(:CORE) # => [0, 18446744073709551615]
See Process.setrlimit
.
Not available on all platforms.
Sets limits for the current process for the given resource
to cur_limit
(soft limit) and max_limit
(hard limit); returns nil
.
Argument resource
specifies the resource whose limits are to be set; the argument may be given as a symbol, as a string, or as a constant beginning with Process::RLIMIT_
(e.g., :CORE
, 'CORE'
, or Process::RLIMIT_CORE
.
The resources available and supported are system-dependent, and may include (here expressed as symbols):
:AS
: Total available memory (bytes) (SUSv3, NetBSD, FreeBSD, OpenBSD except 4.4BSD-Lite).
:CORE
: Core size (bytes) (SUSv3).
:CPU
: CPU time (seconds) (SUSv3).
:DATA
: Data
segment (bytes) (SUSv3).
:FSIZE
: File
size (bytes) (SUSv3).
:MEMLOCK
: Total size for mlock(2) (bytes) (4.4BSD, GNU/Linux).
:MSGQUEUE
: Allocation for POSIX message queues (bytes) (GNU/Linux).
:NICE
: Ceiling on process’s nice(2) value (number) (GNU/Linux).
:NOFILE
: File
descriptors (number) (SUSv3).
:NPROC
: Number of processes for the user (number) (4.4BSD, GNU/Linux).
:NPTS
: Number of pseudo terminals (number) (FreeBSD).
:RSS
: Resident memory size (bytes) (4.2BSD, GNU/Linux).
:RTPRIO
: Ceiling on the process’s real-time priority (number) (GNU/Linux).
:RTTIME
: CPU time for real-time process (us) (GNU/Linux).
:SBSIZE
: All socket buffers (bytes) (NetBSD, FreeBSD).
:SIGPENDING
: Number of queued signals allowed (signals) (GNU/Linux).
:STACK
: Stack size (bytes) (SUSv3).
Arguments cur_limit
and max_limit
may be:
Integers (max_limit
should not be smaller than cur_limit
).
Symbol
:SAVED_MAX
, string 'SAVED_MAX'
, or constant Process::RLIM_SAVED_MAX
: saved maximum limit.
Symbol
:SAVED_CUR
, string 'SAVED_CUR'
, or constant Process::RLIM_SAVED_CUR
: saved current limit.
Symbol
:INFINITY
, string 'INFINITY'
, or constant Process::RLIM_INFINITY
: no limit on resource.
This example raises the soft limit of core size to the hard limit to try to make core dump possible:
Process.setrlimit(:CORE, Process.getrlimit(:CORE)[1])
Not available on all platforms.
Sets the supplemental group access list; the new list includes:
The group IDs of those groups to which the user given by username
belongs.
The group ID gid
.
Example:
Process.groups # => [0, 1, 2, 3, 4, 6, 10, 11, 20, 26, 27] Process.initgroups('me', 30) # => [30, 6, 10, 11] Process.groups # => [30, 6, 10, 11]
Not available on all platforms.