Class: Toys::Utils::Exec::Controller
- Inherits:
-
Object
- Object
- Toys::Utils::Exec::Controller
- Defined in:
- core-docs/toys/utils/exec.rb
Overview
Defined in the toys-core gem
An object that controls a subprocess. This object is returned from an execution running in the background, or is yielded to a control block for an execution running in the foreground. You can use this object to interact with the subcommand's streams, send signals to the process, and get its result.
Instance Attribute Summary collapse
-
#err ⇒ IO?
readonly
The subcommand's standard error stream (which can be read from).
-
#exception ⇒ Exception?
readonly
The exception raised when the process failed to start.
-
#in ⇒ IO?
readonly
The subcommand's standard input stream (which can be written to).
-
#name ⇒ Object
readonly
The subcommand's name.
-
#out ⇒ IO?
readonly
The subcommand's standard output stream (which can be read from).
-
#pid ⇒ Integer?
readonly
The process ID.
Instance Method Summary collapse
-
#capture(which) ⇒ self
Captures the remaining data in the given stream.
-
#capture_err ⇒ self
Captures the remaining data in the standard error stream.
-
#capture_out ⇒ self
Captures the remaining data in the standard output stream.
-
#executing? ⇒ Boolean
Determine whether the subcommand is still executing.
-
#kill(sig) ⇒ self
(also: #signal)
Send the given signal to the process.
-
#redirect(which, io, *io_args) ⇒ self
Redirects the remainder of the given stream.
-
#redirect_err(io, *io_args) ⇒ self
Redirects the remainder of the standard error stream.
-
#redirect_in(io, *io_args) ⇒ self
Redirects the remainder of the standard input stream.
-
#redirect_out(io, *io_args) ⇒ self
Redirects the remainder of the standard output stream.
-
#result(timeout: nil) ⇒ Toys::Utils::Exec::Result?
Wait for the subcommand to complete, and return a result object.
Instance Attribute Details
#err ⇒ IO? (readonly)
The subcommand's standard error stream (which can be read from).
468 469 470 |
# File 'core-docs/toys/utils/exec.rb', line 468 def err @err end |
#exception ⇒ Exception? (readonly)
The exception raised when the process failed to start.
Exactly one of #exception and #pid will be non-nil.
488 489 490 |
# File 'core-docs/toys/utils/exec.rb', line 488 def exception @exception end |
#in ⇒ IO? (readonly)
The subcommand's standard input stream (which can be written to).
450 451 452 |
# File 'core-docs/toys/utils/exec.rb', line 450 def in @in end |
#name ⇒ Object (readonly)
The subcommand's name.
441 442 443 |
# File 'core-docs/toys/utils/exec.rb', line 441 def name @name end |
#out ⇒ IO? (readonly)
The subcommand's standard output stream (which can be read from).
459 460 461 |
# File 'core-docs/toys/utils/exec.rb', line 459 def out @out end |
#pid ⇒ Integer? (readonly)
The process ID.
Exactly one of #exception and #pid will be non-nil.
478 479 480 |
# File 'core-docs/toys/utils/exec.rb', line 478 def pid @pid end |
Instance Method Details
#capture(which) ⇒ self
Captures the remaining data in the given stream. After calling this, do not read directly from the stream.
497 498 499 |
# File 'core-docs/toys/utils/exec.rb', line 497 def capture(which) # Source available in the toys-core gem end |
#capture_err ⇒ self
Captures the remaining data in the standard error stream. After calling this, do not read directly from the stream.
517 518 519 |
# File 'core-docs/toys/utils/exec.rb', line 517 def capture_err # Source available in the toys-core gem end |
#capture_out ⇒ self
Captures the remaining data in the standard output stream. After calling this, do not read directly from the stream.
507 508 509 |
# File 'core-docs/toys/utils/exec.rb', line 507 def capture_out # Source available in the toys-core gem end |
#executing? ⇒ Boolean
Determine whether the subcommand is still executing
614 615 616 |
# File 'core-docs/toys/utils/exec.rb', line 614 def executing? # Source available in the toys-core gem end |
#kill(sig) ⇒ self Also known as: signal
Send the given signal to the process. The signal can be specified by name or number.
604 605 606 |
# File 'core-docs/toys/utils/exec.rb', line 604 def kill(sig) # Source available in the toys-core gem end |
#redirect(which, io, *io_args) ⇒ self
Redirects the remainder of the given stream.
You can specify the stream as an IO or IO-like object, or as a file
specified by its path. If specifying a file, you can optionally
provide the mode and permissions for the call to File#open. You can
also specify the value :null to indicate the null file.
After calling this, do not interact directly with the stream.
537 538 539 |
# File 'core-docs/toys/utils/exec.rb', line 537 def redirect(which, io, *io_args) # Source available in the toys-core gem end |
#redirect_err(io, *io_args) ⇒ self
Redirects the remainder of the standard error stream.
You can specify the stream as an IO or IO-like object, or as a file
specified by its path. If specifying a file, you can optionally
provide the mode and permissions for the call to File#open.
After calling this, do not interact directly with the stream.
593 594 595 |
# File 'core-docs/toys/utils/exec.rb', line 593 def redirect_err(io, *io_args) # Source available in the toys-core gem end |
#redirect_in(io, *io_args) ⇒ self
Redirects the remainder of the standard input stream.
You can specify the stream as an IO or IO-like object, or as a file
specified by its path. If specifying a file, you can optionally
provide the mode and permissions for the call to File#open. You can
also specify the value :null to indicate the null file.
After calling this, do not interact directly with the stream.
556 557 558 |
# File 'core-docs/toys/utils/exec.rb', line 556 def redirect_in(io, *io_args) # Source available in the toys-core gem end |
#redirect_out(io, *io_args) ⇒ self
Redirects the remainder of the standard output stream.
You can specify the stream as an IO or IO-like object, or as a file
specified by its path. If specifying a file, you can optionally
provide the mode and permissions for the call to File#open. You can
also specify the value :null to indicate the null file.
After calling this, do not interact directly with the stream.
575 576 577 |
# File 'core-docs/toys/utils/exec.rb', line 575 def redirect_out(io, *io_args) # Source available in the toys-core gem end |
#result(timeout: nil) ⇒ Toys::Utils::Exec::Result?
Wait for the subcommand to complete, and return a result object.
Closes the control streams if present. The stdin stream is always closed, even if the call times out. The stdout and stderr streams are closed only after the command terminates.
630 631 632 |
# File 'core-docs/toys/utils/exec.rb', line 630 def result(timeout: nil) # Source available in the toys-core gem end |