ExQuality.OutputCollector (ExQuality v0.13.0)

View Source

Collects command output without streaming to console.

Implements the Collectable protocol for use with System.cmd/3's :into option. Stores all output in memory for later retrieval.

Example

collector = ExQuality.OutputCollector.new()
{_output, _exit_code} = System.cmd("mix", ["compile"], into: collector)
output = ExQuality.OutputCollector.get_output(collector)

Watching output as it arrives

A collector can also be given an :on_line handler, called with each complete line as the command produces it:

collector = ExQuality.OutputCollector.new(on_line: &IO.puts/1)

A stage whose tool can stall for minutes needs this to report progress while it happens; the collected output is only available once the command has exited. Lines are reassembled here because a chunk arrives at whatever boundary the port gives it, which is rarely a line.

Summary

Functions

Retrieves the collected output as a binary string.

Creates a new output collector.

Types

t()

@type t() :: %ExQuality.OutputCollector{pid: pid()}

Functions

get_output(output_collector)

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

Retrieves the collected output as a binary string.

new(opts \\ [])

@spec new(keyword()) :: t()

Creates a new output collector.

Options

  • :on_line - a one-argument function called with each complete line of output as it arrives, without its trailing newline.