All chapters21
On this page

Guide · Chapter 6

Processes and System

Run commands, consume output, and inspect system state.

The safety boundary between run and shell

example.hhy
run(["git", "log", "--oneline"], { timeout: 5s })
    |> stdout_lines
    |> take(10)
    |> print

run(argv, options?) passes List<String> directly to the OS without a shell, so spaces, globs, $, redirects, and pipes are not reinterpreted. Use shell(command, options?) only when shell syntax is intentional; the Checker emits a safety hint.

OptionPurpose
cwdChild working-directory Path
envOverrides only the child environment
stdinText supplied on standard input
timeoutMaximum command duration
max_outputstdout and stderr capture limit

CommandResult

run and shell wait by default and return CommandResult. A nonzero child exit code is not automatically an HHY Error; inspect exit_code for business success.

FieldContents
exit_codeChild exit status
stdoutStandard-output String
stderrStandard-error String
durationCommand Duration

A nonzero exit_code does not automatically become an HHY Error; interpret it according to the command. stdout_lines(result) exposes captured output as a line Stream.

Process snapshots and fields

processes() returns a current Stream<Process> snapshot. Process is not a Map and exposes read-only pid, name, cpu, memory, status, and command fields. Explicitly map ordinary fields before JSON encoding.

args, env, system, and stdin

ValueContents
argsList<String> excluding the script path
envRead-only environment view
systemOS, architecture, host, CPU, memory, and directories
stdin_lines()Standard-input line Stream
example.hhy
if length(args) != 1 {
    print_error("usage: script.hhy <input>")
    exit(3)
}

let input = path(args[0])

Look up the complete API

Processes and system API Reference →Look up complete signatures for run, shell, processes, stdin_lines, and every.