zena:process

zena
import {…} from 'zena:process';

zena:process — spawning host processes from Zena programs.

WASI itself cannot create processes, so these services are host imports (wasm module zena_process) that only the zena-cli host provides — and only to invocations it trusts: its own orchestrator programs (the bench and test runners), repo tests, and zena-cli run when passed --allow-spawn (or ZENA_ALLOW_SPAWN=1). Everywhere else the host links trapping stubs, so importing this library always compiles for wasi-family targets, but calling into it without the grant fails loudly at the first call — spawning is a deliberate sandbox escape and must stay opt-in.

Strings cross the boundary via the $string* helper exports every Zena module carries; process handles are opaque host references, so their lifetime is managed by the GC like any other object.

Classes

ProcessResult

zena
class ProcessResult

The captured outcome of a finished process.

Constructors
zena
new()
#
Properties
zena
exitCode: i32
#
zena
stdout: String
#
zena
stderr: String
#
zena
wallNanos: i64
#

Wall-clock nanoseconds from spawn to exit.

zena
timedOut: boolean
#

True when the process overran a waitFor deadline and was killed rather than exiting on its own. Whatever it had written before the deadline is still in stdout/stderr.

Methods
zena
succeeded(): boolean
#

Process

zena
final class Process

A running child process. Both stdout and stderr are captured by the host (there is no streaming in v1); wait() blocks until the process exits and returns the captured outcome. Waiting more than once returns the same result.

Constructors
zena
new(proc: ProcRef)
#
Methods
zena
wait(): ProcessResult
#
zena
waitFor(millis: i64): ProcessResult
#

Waits at most millis for the process to exit, killing it if it overruns — the result then has timedOut set, and holds whatever it managed to write first. A non-positive millis waits forever, so a caller can disable its timeout without branching. Waiting again returns the same result.

Functions

spawnIn

zena
function spawnIn(argv: Array<String>, cwd: String | null): Process

Start a process without waiting for it. argv[0] is the executable (resolved against PATH by the host); the child inherits the host's environment and, with cwd == null, its working directory. Spawning several processes and waiting on each is how a caller runs work in parallel. A process that cannot be started at all (e.g. the executable does not exist) traps with a descriptive message when waited on.

spawn

zena
function spawn(argv: Array<String>): Process

spawnIn with the host's working directory.

runIn

zena
function runIn(argv: Array<String>, cwd: String | null): ProcessResult

Run a process to completion in the given working directory.

run

zena
function run(argv: Array<String>): ProcessResult

Run a process to completion in the host's working directory.