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, from the caller’s stdin
, 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 3-element array containing:
The stdin
stream of the first child process.
The stdout
stream of the last child process.
An array of the wait threads for all of the child processes.
Example:
first_stdin, last_stdout, wait_threads = Open3.pipeline_rw('sort', 'cat -n') # => [#<IO:fd 20>, #<IO:fd 21>, [#<Process::Waiter:0x000055e8de29ab40 sleep>, #<Process::Waiter:0x000055e8de29a690 sleep>]] first_stdin.puts("foo\nbar\nbaz") first_stdin.close # Send EOF to sort. puts last_stdout.read 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, the stdout
stream of the last child, and an array of the wait processes:
Open3.pipeline_rw('sort', 'cat -n') do |first_stdin, last_stdout, wait_threads| first_stdin.puts "foo\nbar\nbaz" first_stdin.close # send EOF to sort. puts last_stdout.read 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.
Returns a clock resolution as determined by POSIX function clock_getres():
Process.clock_getres(:CLOCK_REALTIME) # => 1.0e-09
See Process.clock_gettime
for the values of clock_id
and unit
.
Examples:
Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :float_microsecond) # => 0.001 Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :float_millisecond) # => 1.0e-06 Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :float_second) # => 1.0e-09 Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :microsecond) # => 0 Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :millisecond) # => 0 Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :nanosecond) # => 1 Process.clock_getres(:CLOCK_PROCESS_CPUTIME_ID, :second) # => 0
In addition to the values for unit
supported in Process.clock_gettime
, this method supports :hertz
, the integer number of clock ticks per second (which is the reciprocal of :float_second
):
Process.clock_getres(:TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID, :hertz) # => 100.0 Process.clock_getres(:TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID, :float_second) # => 0.01
Accuracy: Note that the returned resolution may be inaccurate on some platforms due to underlying bugs. Inaccurate resolutions have been reported for various clocks including :CLOCK_MONOTONIC
and :CLOCK_MONOTONIC_RAW
on Linux, macOS, BSD or AIX platforms, when using ARM processors, or when using virtualization.
Indicates whether this DH
instance has a private key associated with it or not. The private key may be retrieved with DH#priv_key.
Verifies whether the signature is valid given the message digest input. It does so by validating sig
using the public key of this DSA
instance.
Deprecated in version 3.0. Consider using PKey::PKey#sign_raw
and PKey::PKey#verify_raw
instead.
digest
A message digest of the original input data to be signed.
sig
A DSA signature value.
Indicates whether this DSA
instance has a private key associated with it or not. The private key may be retrieved with DSA#private_key.
Returns whether this EC
instance has a private key. The private key (BN
) can be retrieved with EC#private_key
.
Does this keypair contain a private key?
The list of cipher suites configured for this context.
Sets the list of available cipher suites for this context. Note in a server context some ciphers require the appropriate certificates. For example, an RSA cipher suite can only be chosen when an RSA certificate is available.
Sets the list of available TLSv1.3 cipher suites for this context.
Writes string to the SSL
connection.
Sends “close notify” to the peer and tries to shut down the SSL
connection gracefully.
Returns the cipher suite actually used in the current session, or nil if no session has been established.
A description of the current connection state. This is for diagnostic purposes only.
Sets the server hostname used for SNI. This needs to be set before SSLSocket#connect
.
See TCPServer#listen
for details.
Performs the certificate verification using the parameters set to stctx.
See also the man page X509_verify_cert(3).