Class: Microsandbox::ExecOutput

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ ExecOutput

Returns a new instance of ExecOutput.

Parameters:

  • data (Hash)

    the native exec result hash



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_codeInteger (readonly)

Returns the process exit code.

Returns:

  • (Integer)

    the process exit code



11
12
13
# File 'lib/microsandbox/exec_output.rb', line 11

def exit_code
  @exit_code
end

#stderr_bytesString (readonly)

Returns raw stderr bytes (ASCII-8BIT).

Returns:

  • (String)

    raw stderr bytes (ASCII-8BIT)



15
16
17
# File 'lib/microsandbox/exec_output.rb', line 15

def stderr_bytes
  @stderr_bytes
end

#stdout_bytesString (readonly)

Returns raw stdout bytes (ASCII-8BIT).

Returns:

  • (String)

    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.

Returns:

  • (Boolean)

    whether the process exited non-zero



31
32
33
# File 'lib/microsandbox/exec_output.rb', line 31

def failure?
  !@success
end

#inspectObject



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

#stderrString

Returns stderr decoded as UTF-8.

Returns:

  • (String)

    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

#stdoutString

Returns stdout decoded as UTF-8.

Returns:

  • (String)

    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.

Returns:

  • (Boolean)

    whether the process exited with status 0



26
27
28
# File 'lib/microsandbox/exec_output.rb', line 26

def success?
  @success
end

#to_sString

Returns stdout decoded as UTF-8 (alias for #stdout).

Returns:

  • (String)

    stdout decoded as UTF-8 (alias for #stdout)



46
47
48
# File 'lib/microsandbox/exec_output.rb', line 46

def to_s
  stdout
end