Get the default RubyGems API host. This is normally https://rubygems.org
.
Set
the default RubyGems API host.
Copies a file entry. See install(1).
Arguments src
(a single path or an array of paths) and dest
(a single path) should be interpretable as paths;
If the entry at dest
does not exist, copies from src
to dest
:
File.read('src0.txt') # => "aaa\n" File.exist?('dest0.txt') # => false FileUtils.install('src0.txt', 'dest0.txt') File.read('dest0.txt') # => "aaa\n"
If dest
is a file entry, copies from src
to dest
, overwriting:
File.read('src1.txt') # => "aaa\n" File.read('dest1.txt') # => "bbb\n" FileUtils.install('src1.txt', 'dest1.txt') File.read('dest1.txt') # => "aaa\n"
If dest
is a directory entry, copies from src
to dest/src
, overwriting if necessary:
File.read('src2.txt') # => "aaa\n" File.read('dest2/src2.txt') # => "bbb\n" FileUtils.install('src2.txt', 'dest2') File.read('dest2/src2.txt') # => "aaa\n"
If src
is an array of paths and dest
points to a directory, copies each path path
in src
to dest/path
:
File.file?('src3.txt') # => true File.file?('src3.dat') # => true FileUtils.mkdir('dest3') FileUtils.install(['src3.txt', 'src3.dat'], 'dest3') File.file?('dest3/src3.txt') # => true File.file?('dest3/src3.dat') # => true
Keyword arguments:
group: group
- changes the group if not nil
, using File.chown
.
mode: permissions
- changes the permissions. using File.chmod
.
noop: true
- does not copy entries; returns nil
.
owner: owner
- changes the owner if not nil
, using File.chown
.
preserve: true
- preserve timestamps using File.utime
.
verbose: true
- prints an equivalent command:
FileUtils.install('src0.txt', 'dest0.txt', noop: true, verbose: true) FileUtils.install('src1.txt', 'dest1.txt', noop: true, verbose: true) FileUtils.install('src2.txt', 'dest2', noop: true, verbose: true)
Output:
install -c src0.txt dest0.txt install -c src1.txt dest1.txt install -c src2.txt dest2
Related: methods for copying.
Copies a file entry. See install(1).
Arguments src
(a single path or an array of paths) and dest
(a single path) should be interpretable as paths;
If the entry at dest
does not exist, copies from src
to dest
:
File.read('src0.txt') # => "aaa\n" File.exist?('dest0.txt') # => false FileUtils.install('src0.txt', 'dest0.txt') File.read('dest0.txt') # => "aaa\n"
If dest
is a file entry, copies from src
to dest
, overwriting:
File.read('src1.txt') # => "aaa\n" File.read('dest1.txt') # => "bbb\n" FileUtils.install('src1.txt', 'dest1.txt') File.read('dest1.txt') # => "aaa\n"
If dest
is a directory entry, copies from src
to dest/src
, overwriting if necessary:
File.read('src2.txt') # => "aaa\n" File.read('dest2/src2.txt') # => "bbb\n" FileUtils.install('src2.txt', 'dest2') File.read('dest2/src2.txt') # => "aaa\n"
If src
is an array of paths and dest
points to a directory, copies each path path
in src
to dest/path
:
File.file?('src3.txt') # => true File.file?('src3.dat') # => true FileUtils.mkdir('dest3') FileUtils.install(['src3.txt', 'src3.dat'], 'dest3') File.file?('dest3/src3.txt') # => true File.file?('dest3/src3.dat') # => true
Keyword arguments:
group: group
- changes the group if not nil
, using File.chown
.
mode: permissions
- changes the permissions. using File.chmod
.
noop: true
- does not copy entries; returns nil
.
owner: owner
- changes the owner if not nil
, using File.chown
.
preserve: true
- preserve timestamps using File.utime
.
verbose: true
- prints an equivalent command:
FileUtils.install('src0.txt', 'dest0.txt', noop: true, verbose: true) FileUtils.install('src1.txt', 'dest1.txt', noop: true, verbose: true) FileUtils.install('src2.txt', 'dest2', noop: true, verbose: true)
Output:
install -c src0.txt dest0.txt install -c src1.txt dest1.txt install -c src2.txt dest2
Related: methods for copying.
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.
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.
Returns the singleton instance.
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.
Specifies the handling of signals. The first parameter is a signal name (a string such as “SIGALRM”, “SIGUSR1”, and so on) or a signal number. The characters “SIG” may be omitted from the signal name. The command or block specifies code to be run when the signal is raised. If the command is the string “IGNORE” or “SIG_IGN”, the signal will be ignored. If the command is “DEFAULT” or “SIG_DFL”, the Ruby’s default handler will be invoked. If the command is “EXIT”, the script will be terminated by the signal. If the command is “SYSTEM_DEFAULT”, the operating system’s default handler will be invoked. Otherwise, the given command or block will be run. The special signal name “EXIT” or signal number zero will be invoked just prior to program termination. trap returns the previous handler for the given signal.
Signal.trap(0, proc { puts "Terminating: #{$$}" }) Signal.trap("CLD") { puts "Child died" } fork && Process.wait
produces:
Terminating: 27461 Child died Terminating: 27460
Returns a list of signal names mapped to the corresponding underlying signal numbers.
Signal.list #=> {"EXIT"=>0, "HUP"=>1, "INT"=>2, "QUIT"=>3, "ILL"=>4, "TRAP"=>5, "IOT"=>6, "ABRT"=>6, "FPE"=>8, "KILL"=>9, "BUS"=>7, "SEGV"=>11, "SYS"=>31, "PIPE"=>13, "ALRM"=>14, "TERM"=>15, "URG"=>23, "STOP"=>19, "TSTP"=>20, "CONT"=>18, "CHLD"=>17, "CLD"=>17, "TTIN"=>21, "TTOU"=>22, "IO"=>29, "XCPU"=>24, "XFSZ"=>25, "VTALRM"=>26, "PROF"=>27, "WINCH"=>28, "USR1"=>10, "USR2"=>12, "PWR"=>30, "POLL"=>29}
Returns the octet string representation of the elliptic curve point.
conversion_form specifies how the point is converted. Possible values are:
:compressed
:uncompressed
:hybrid
@foo = 1 ^^^^^^^^