Skip to content

std/process ​

From the spec

This page is spec/std/process.md, the specification the compiler and the backends are written from. It is rebuilt from the spec with every deploy (how).

The running program (weft run <file> [args…]): its arguments, environment, input, output and exit, and the programs it runs. Files are std/fs's (fs.md). Sandboxed user code can't import it (sandbox.md).

args(): string[]the arguments after the file (or project)
env(name: string): string?an environment variable, null when it isn't set
exit(code: number): neverends the program with code once the current turn is done (the turn ends at once, as a stop ends it: no defer runs, nothing reports it)
stdout(text: string), stderr(text: string)write text as it is, no line break added; log lines written before come first
stdin(): Inputstandard input, read as it arrives: line(): Task<string? ! ProcessError> (the next line without its \n or \r\n; null at the end), text() (the rest), chunk(): Task<Bytes? ! ProcessError> (the next bytes as they come). One reader, shared
run(command, args = [], options?): Task<Output ! ProcessError>runs a program to its end: Output = { code, signal, success, stdout, stderr } (the output as UTF-8 text)
spawn(command, args = [], options?): Task<Child ! ProcessError>starts a program: Child = { pid, stdout(), stderr(), write(data), closeStdin(), wait(), kill() }
  • Programs start without a shell: command is found on PATH (or is a path) and args are passed as they are, so nothing in them is interpreted. SpawnOptions = { cwd?, env?: [string, string][], clearEnv?, stdin?: Bytes | string, timeout? }: the working directory, variables added to this program's environment (or, with clearEnv, the only ones), and for run the input and a time limit in ms (it is killed past it, and run fails). A Child's stdout() and stderr() give its output's next bytes as they come (null at the end), write sends to its input (await each), closeStdin ends its input, wait(): Task<Exit> settles when it ends (Exit = { code: number?, signal: number?, success }: code is null when a signal ended it; success is code 0), kill sends SIGKILL. What can't be done (a program that can't start, input that can't be written or read, run's timeout) fails with ProcessError { message }. A child still running when the program ends is killed.
  • std/log's log writes a line to standard output, warn and error to standard error, as they are made.
  • The exit status is exit's code, else the number an exported main(args) returned, else 1 when a module's load or main failed (error: and the error as JSON on stderr), a turn panicked or stopped, or a task's error went unobserved, else 0. A program ends when nothing is left that could happen (server.md, The event loop); SIGINT and SIGTERM end a serving program once its servers have closed.

Weft is in development. The reference is the spec as it stands today.