Class: Microsandbox::ExecOutput
- Inherits:
-
Object
- Object
- Microsandbox::ExecOutput
- Defined in:
- lib/microsandbox/exec_output.rb
Overview
The result of a completed ‘exec`/`shell` call.
‘stdout`/`stderr` return the captured bytes decoded as UTF-8 (lenient — the bytes are preserved even if they are not valid UTF-8); use `stdout_bytes`/ `stderr_bytes` for the raw ASCII-8BIT bytes.
Instance Attribute Summary collapse
-
#exit_code ⇒ Integer
readonly
The process exit code.
-
#stderr_bytes ⇒ String
readonly
Raw stderr bytes (ASCII-8BIT).
-
#stdout_bytes ⇒ String
readonly
Raw stdout bytes (ASCII-8BIT).
Instance Method Summary collapse
-
#failure? ⇒ Boolean
Whether the process exited non-zero.
-
#initialize(data) ⇒ ExecOutput
constructor
A new instance of ExecOutput.
- #inspect ⇒ Object
-
#stderr ⇒ String
Stderr decoded as UTF-8.
-
#stdout ⇒ String
Stdout decoded as UTF-8.
-
#success? ⇒ Boolean
Whether the process exited with status 0.
-
#to_s ⇒ String
Stdout decoded as UTF-8 (alias for #stdout).
Constructor Details
#initialize(data) ⇒ ExecOutput
Returns a new instance of ExecOutput.
18 19 20 21 22 23 |
# File 'lib/microsandbox/exec_output.rb', line 18 def initialize(data) @exit_code = data["exit_code"] @success = data["success"] @stdout_bytes = data["stdout"] @stderr_bytes = data["stderr"] end |
Instance Attribute Details
#exit_code ⇒ Integer (readonly)
Returns the process exit code.
11 12 13 |
# File 'lib/microsandbox/exec_output.rb', line 11 def exit_code @exit_code end |
#stderr_bytes ⇒ String (readonly)
Returns raw stderr bytes (ASCII-8BIT).
15 16 17 |
# File 'lib/microsandbox/exec_output.rb', line 15 def stderr_bytes @stderr_bytes end |
#stdout_bytes ⇒ String (readonly)
Returns raw stdout bytes (ASCII-8BIT).
13 14 15 |
# File 'lib/microsandbox/exec_output.rb', line 13 def stdout_bytes @stdout_bytes end |
Instance Method Details
#failure? ⇒ Boolean
Returns whether the process exited non-zero.
31 32 33 |
# File 'lib/microsandbox/exec_output.rb', line 31 def failure? !@success end |
#inspect ⇒ Object
50 51 52 53 |
# File 'lib/microsandbox/exec_output.rb', line 50 def inspect "#<Microsandbox::ExecOutput exit_code=#{@exit_code} success=#{@success} " \ "stdout=#{stdout.bytesize}B stderr=#{stderr.bytesize}B>" end |
#stderr ⇒ String
Returns stderr decoded as UTF-8.
41 42 43 |
# File 'lib/microsandbox/exec_output.rb', line 41 def stderr @stderr ||= @stderr_bytes.dup.force_encoding(Encoding::UTF_8) end |
#stdout ⇒ String
Returns stdout decoded as UTF-8.
36 37 38 |
# File 'lib/microsandbox/exec_output.rb', line 36 def stdout @stdout ||= @stdout_bytes.dup.force_encoding(Encoding::UTF_8) end |
#success? ⇒ Boolean
Returns whether the process exited with status 0.
26 27 28 |
# File 'lib/microsandbox/exec_output.rb', line 26 def success? @success end |
#to_s ⇒ String
Returns stdout decoded as UTF-8 (alias for #stdout).
46 47 48 |
# File 'lib/microsandbox/exec_output.rb', line 46 def to_s stdout end |