Process
Process module: OS process interaction.
run/2 runs a command and waits for it to finish, returning the exit code and captured stdout. run_stream/2 returns a Seq(String) of output lines for pipeline-style processing without buffering the whole output.
The command is looked up in PATH. A command that cannot be executed (not found, not executable) is an Err from the spawning call itself ("cannot execute <cmd>: <reason>"), never an Ok with exit code 127. The child inherits the current working directory and environment (including set_env), starts with no signals blocked and every signal at its default action.
env/1 and set_env/2 read and write OS environment variables. cwd/0, argv/0, pid/0 expose the current process context. exit/1 terminates the VM with the given exit code.
Types
Result of a completed subprocess. ProcessResult(exit_code, stdout, stderr)
Handle for an asynchronously-spawned subprocess (non-blocking). LiveProcess(pid, stream_id) — both fields are opaque implementation details.
Functions
Returns the command-line arguments as List(String) (argv[0] is the executable).
Returns the current working directory.
Get the value of an environment variable. Returns Some(value) or None.
Terminate the process with the given exit code.
Extract the exit code from a ProcessResult.
Send SIGTERM to the live process.
True if the command exited with code 0.
Returns the OS-level PID of the current process.
Read one line from the live process's stdout. Returns Some(line) for each output line, or None when the process has closed its stdout (typically on exit). Blocks until a full line is available.
Run command with args, wait for it to finish. Returns Ok(ProcessResult) with the exit code and captured stdout/stderr, or Err(msg) when the command could not be started: "cannot execute <cmd>: <reason>" for a missing or non-executable program. A program that runs and fails is still Ok, with its non-zero exit code.
match Process.run("git", ["status"]) do
Ok(r) -> println(Process.stdout(r))
Err(msg) -> println(msg) -- e.g. "cannot execute git: No such file or directory"
endRun command and return its stdout as a Seq(String) of lines. Returns Ok(Seq), or Err(msg) when the command cannot be executed (as for run). The command runs to completion and its stdout is read in full before the Seq is returned; the Seq is not a live stream of the running process.
Set an environment variable.
Spawn a command asynchronously (non-blocking). Returns Ok(LiveProcess) immediately — the child process starts running in the background. Use read_line to consume its stdout, kill to terminate it, and wait_proc to reap its exit code. Returns Err(msg) when the command cannot be executed: "cannot execute <cmd>: <reason>".
Extract captured stderr from a ProcessResult.
Extract captured stdout from a ProcessResult.
Wait for the live process to exit and return its exit code. Also closes the stdout channel. Should be called after the process exits (read_line returned None) or after kill.
Write raw bytes to the live process's stdin. The data is flushed immediately so the child process sees it without delay. Include a trailing newline if the child reads line-by-line.