Bash.Execution (Bash v0.3.0)

Copy Markdown View Source

Represents a single command execution with its own I/O streams.

Each command in a session gets its own Execution struct with separate StringIO devices for stdout and stderr. This enables:

  • Per-command output inspection after execution
  • Pipeline wiring (previous stdout becomes next stdin)
  • Merged enumeration across all executions

Example

# Create execution for a command
{:ok, exec} = Execution.new("echo hello")

# Write to its streams
IO.puts(exec.stdout, "hello")

# Get output after completion
Execution.stdout_contents(exec)  # => "hello\n"

Summary

Functions

Closes the StringIO devices for this execution.

Marks the execution as completed with the given exit code.

Creates a new Execution with fresh StringIO streams.

Gets the stderr contents from the execution.

Gets the stdout contents from the execution.

Types

t()

@type t() :: %Bash.Execution{
  command: String.t(),
  completed_at: DateTime.t() | nil,
  exit_code: 0..255 | nil,
  started_at: DateTime.t(),
  stderr: pid(),
  stdout: pid()
}

Functions

close(execution)

@spec close(t()) :: :ok

Closes the StringIO devices for this execution.

Should be called when the execution is no longer needed to free resources.

complete(exec, exit_code)

@spec complete(t(), 0..255) :: t()

Marks the execution as completed with the given exit code.

new(command)

@spec new(String.t()) :: {:ok, t()} | {:error, term()}

Creates a new Execution with fresh StringIO streams.

Examples

{:ok, exec} = Execution.new("echo hello")
IO.write(exec.stdout, "hello\n")

stderr_contents(execution)

@spec stderr_contents(t()) :: String.t()

Gets the stderr contents from the execution.

Returns the accumulated output written to stderr.

stdout_contents(execution)

@spec stdout_contents(t()) :: String.t()

Gets the stdout contents from the execution.

Returns the accumulated output written to stdout.