Puck.Sandbox.Runtime.ExecResult (Puck v0.2.12)

Copy Markdown View Source

Struct representing the result of executing a command in a sandbox.

Fields

  • stdout - Standard output from the command
  • stderr - Standard error from the command
  • exit_code - Exit code of the command (0 typically means success)

Examples

%Puck.Sandbox.Runtime.ExecResult{
  stdout: "hello world",
  stderr: "",
  exit_code: 0
}

Summary

Functions

Creates a new ExecResult with the given attributes.

Returns the output (stdout if present, otherwise stderr).

Returns true if the command executed successfully (exit code 0).

Types

t()

@type t() :: %Puck.Sandbox.Runtime.ExecResult{
  exit_code: non_neg_integer(),
  stderr: String.t(),
  stdout: String.t()
}

Functions

new(attrs \\ [])

Creates a new ExecResult with the given attributes.

Examples

iex> Puck.Sandbox.Runtime.ExecResult.new(stdout: "hello", exit_code: 0)
%Puck.Sandbox.Runtime.ExecResult{stdout: "hello", stderr: "", exit_code: 0}

output(exec_result)

Returns the output (stdout if present, otherwise stderr).

Useful when you just want the command output regardless of stream.

Examples

iex> result = Puck.Sandbox.Runtime.ExecResult.new(stdout: "hello", exit_code: 0)
iex> Puck.Sandbox.Runtime.ExecResult.output(result)
"hello"

iex> result = Puck.Sandbox.Runtime.ExecResult.new(stderr: "error message", exit_code: 1)
iex> Puck.Sandbox.Runtime.ExecResult.output(result)
"error message"

success?(exec_result)

Returns true if the command executed successfully (exit code 0).

Examples

iex> result = Puck.Sandbox.Runtime.ExecResult.new(exit_code: 0)
iex> Puck.Sandbox.Runtime.ExecResult.success?(result)
true

iex> result = Puck.Sandbox.Runtime.ExecResult.new(exit_code: 1)
iex> Puck.Sandbox.Runtime.ExecResult.success?(result)
false