E2bEx.CommandHandle (E2bEx v0.1.0)

Copy Markdown View Source

A handle to a background command started with E2bEx.Commands.start/4 (or reconnected via E2bEx.Commands.connect/4).

Output is delivered to the subscriber process as messages tagged with the handle's ref:

{ref, {:stdout, binary}}
{ref, {:stderr, binary}}
{ref, {:exit, %E2bEx.CommandResult{}}}   # terminal, any exit code
{ref, {:error, %E2bEx.Error{}}}          # terminal, failure

Consume the message stream or call wait/1 (which drains the stream and returns the result) — not both from the same process.

Summary

Functions

Close the command's stdin (EOF).

Stop streaming from the command without killing it. The envd process keeps running; reconnect with E2bEx.Commands.connect/4. No terminal message is sent.

Kill the command (SIGKILL). {:ok, false} if it was already gone.

The envd process id of the running command.

Send data to the command's stdin (requires start(stdin: true)).

Block until the command finishes and return its result.

Types

t()

@type t() :: %E2bEx.CommandHandle{
  context: map(),
  pid: non_neg_integer(),
  ref: reference(),
  server: pid()
}

Functions

close_stdin(command_handle)

@spec close_stdin(t()) :: :ok | {:error, E2bEx.Error.t()}

Close the command's stdin (EOF).

disconnect(command_handle)

@spec disconnect(t()) :: :ok

Stop streaming from the command without killing it. The envd process keeps running; reconnect with E2bEx.Commands.connect/4. No terminal message is sent.

kill(command_handle)

@spec kill(t()) :: {:ok, boolean()} | {:error, E2bEx.Error.t()}

Kill the command (SIGKILL). {:ok, false} if it was already gone.

pid(command_handle)

@spec pid(t()) :: non_neg_integer()

The envd process id of the running command.

send_stdin(command_handle, data)

@spec send_stdin(t(), binary()) :: :ok | {:error, E2bEx.Error.t()}

Send data to the command's stdin (requires start(stdin: true)).

wait(command_handle)

@spec wait(t()) :: {:ok, E2bEx.CommandResult.t()} | {:error, E2bEx.Error.t()}

Block until the command finishes and return its result.

Drains the intermediate {ref, {:stdout|:stderr, _}} messages from the caller's mailbox and returns on the terminal message: {:ok, %E2bEx.CommandResult{}} for any exit code, or {:error, %E2bEx.Error{}}. Must be called from the subscriber process. Returns {:error, %E2bEx.Error{}} if the handle server crashes.