Appearance
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): never | ends 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(): Input | standard 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:
commandis found onPATH(or is a path) andargsare 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, withclearEnv, the only ones), and forrunthe input and a time limit in ms (it is killed past it, andrunfails). AChild'sstdout()andstderr()give its output's next bytes as they come (nullat the end),writesends to its input (await each),closeStdinends its input,wait(): Task<Exit>settles when it ends (Exit = { code: number?, signal: number?, success }:codeisnullwhen a signal ended it;successis code 0),killsends SIGKILL. What can't be done (a program that can't start, input that can't be written or read,run's timeout) fails withProcessError { message }. A child still running when the program ends is killed. std/log'slogwrites a line to standard output,warnanderrorto standard error, as they are made.- The exit status is
exit's code, else the number an exportedmain(args)returned, else 1 when a module's load ormainfailed (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.