NetRunner.Process (NetRunner v1.2.1)

Copy Markdown View Source

GenServer managing a single OS process lifecycle.

Handles read/write on pipes, graceful shutdown, and exit status tracking. Uses NIF-backed async I/O with enif_select for backpressure.

PTY mode

Pass pty: true to get a pseudo-terminal. This is for interactive and long-running programs (shells, REPLs, curses apps). Key differences from pipe mode:

  • No independent stdin close — the PTY is a single bidirectional FD. Use kill/2 to terminate the process.
  • The terminal echoes input back, so reads include what you wrote.
  • Fast-exiting commands may lose output if you don't read immediately — the PTY buffer is torn down when the slave side closes.
  • For simple commands, use pipe mode (the default).

Summary

Functions

Check if the process is alive.

Wait for the process to exit. Returns {:ok, exit_status}.

Returns a specification to start this module under a supervisor.

Close stdin pipe.

Send a signal to the OS process.

Get the OS PID.

Read from stdout. Blocks until data available or EOF.

Set PTY window size (rows, cols). Only works in PTY mode.

Get accumulated stats.

Write to stdin.

Functions

alive?(process)

Check if the process is alive.

await_exit(process, timeout \\ :infinity)

Wait for the process to exit. Returns {:ok, exit_status}.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

close_stdin(process)

Close stdin pipe.

kill(process, signal \\ :sigterm)

Send a signal to the OS process.

os_pid(process)

Get the OS PID.

read(process, max_bytes \\ 65535)

Read from stdout. Blocks until data available or EOF.

read_stderr(process, max_bytes \\ 65535)

Read from stderr.

set_window_size(process, rows, cols)

Set PTY window size (rows, cols). Only works in PTY mode.

start(cmd, args \\ [], opts \\ [])

start_link(cmd, args \\ [], opts \\ [])

stats(process)

Get accumulated stats.

write(process, data)

Write to stdin.