Bash.ProcessSubst (Bash v0.6.0)

Copy Markdown View Source

GenServer managing process substitution execution.

Process substitution (<(command) and >(command)) creates a temp file via the session's Bash.Filesystem and runs a background command that reads from or writes to it. The temp file path is returned and can be used as a file argument to other commands.

Input Process Substitution

Runs the command, captures its stdout to a binary, and writes the result to a VFS temp file. The parent command reads from this path as if it were a regular file.

diff <(sort file1) <(sort file2)

Output Process Substitution

Creates a temp file path. The parent command writes to it; the substituted command polls for the file to appear and then reads it as stdin.

tee >(gzip > file.gz) >(bzip2 > file.bz2)

Lifecycle

  1. Created via start_link/1 with command AST and session state
  2. Generates a unique temp path in session's temp directory
  3. Spawns background process to run the command
  4. Returns temp file path synchronously
  5. Background process runs until command completes
  6. Cleanup happens on GenServer stop (temp file removed via VFS)

State Machine

stateDiagram-v2
  [*] --> Initialising: start_link/1
  Initialising --> Running: handle_continue setup
  Running --> Done: worker_done message
  Done --> [*]: stop/1

Summary

Functions

Returns a specification to start this module under a supervisor.

Types

direction()

@type direction() :: :input | :output

t()

@type t() :: %Bash.ProcessSubst{
  command_ast: term(),
  direction: direction(),
  os_pid: pos_integer() | nil,
  session_state: map(),
  temp_path: String.t() | nil,
  worker_pid: pid() | nil
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.