Types
Captured child output from std.process.try_run.
status: int | The child's exit status. |
|---|---|
stdout: string | Everything the child wrote to standard output. |
stderr: string | Everything the child wrote to standard error. |
Captured child output from std.process.run*. A failed spawn is code = -1, ok = false, stderr = <error name>.
code: int | The child's exit code, or -1 when the spawn itself failed. |
|---|---|
stdout: string | Everything the child wrote to standard output. |
stderr: string | Everything the child wrote to standard error, or the error name when the spawn failed. |
ok: bool | Whether the child ran and exited zero. |
How many children are running, in total and per tool.
total: int | How many children are running right now. |
|---|---|
by_tool: {string: int} | The same count broken down by program name. |
What a finished child left behind. Pipes are byte strings, as everywhere else in this port — moon strings are bytes and nothing validates encoding, so a probe's JSON and a thumbnail's bytes travel the same way.
stdout: string | Buffered standard output as bytes; empty for a streaming run. |
|---|---|
stderr: string | Buffered standard error as bytes. |
exit_code: int | The child's exit code; a signal is reported negative. |
Where a checked run happens and with what environment. cwd empty means inherit; env entries are "K=V" and extend the current environment.
Deliberately not ProcessOptions, which is the low-level spawn's and also carries the three stdio dispositions. A checked run owns those: it drains both pipes concurrently, so stdout: "inherit" would make it read nothing or hang. An options type whose fields are silently overwritten is worse than two types.
cwd: string | Directory to run in; empty inherits the current one. |
|---|---|
env: [string] | Extra environment entries spelled |
Streaming child spawn configuration.
cwd: string | |
|---|---|
env: [string] | |
stdin: string | |
stdout: string | |
stderr: string |
Internal process ownership handle.
An opaque handle: only std.process can produce one, and its contents are not reachable from moon source.
_handle: NativeHandle | The native resource. |
|---|
Constants
The error name a stopped child fails with, so a caller can tell "I stopped it" from "it failed".
A name, not a message suffix. This used to be failure.message.ends_with(" was cancelled"), which is a string sniff over text a caller may reasonably want to change or translate, and which a genuine failure whose message happened to end that way would satisfy.
Functions
Spawns argv directly with piped stdout/stderr and null stdin.
argv: Program and its arguments; no shell parsing is applied.
async fn main() {
match std.process.try_spawn(["moon", "--version"]) {
ok(child) => {
println(child.pid())
println(await child.wait())
},
err(failure) => println(failure.message),
}
}Result-returning twin of spawn.
argv: Program and its arguments; no shell parsing is applied.
Spawns argv with explicit cwd, environment additions, and stdio dispositions.
argv: Program and its arguments; no shell parsing is applied.options: Working directory, environment additions, and the three stdio dispositions.
Result-returning twin of spawn_opts.
argv: Program and its arguments; no shell parsing is applied.options: Working directory, environment additions, and the three stdio dispositions.
Runs command, buffering both pipes, and fails when the child does.
command: Program and its arguments; no shell parsing is applied.options: Working directory and environment additions for the run.
async fn main() {
let options = std.process.in_dir(".")
let captured = (await std.process.spawn_checked(["moon", "--version"], options)).unwrap()
println(captured.exit_code)
println(captured.stdout)
let streamed = await std.process.spawn_streaming(
["moon", "--version"],
std.process.no_options(),
|line| println("child: " + line),
)
println(streamed.is_ok())
println(std.process.active_subprocesses().total)
}Runs command with stdout streamed line by line to on_line rather than buffered; the returned stdout is empty, as it was in the Bun port.
command: Program and its arguments; no shell parsing is applied.options: Working directory and environment additions for the run.on_line: Called with each stdout line, without its newline.
Runs command streaming, and terminates it if should_stop starts reporting true. A run stopped that way fails with a cancellation message rather than the child's exit status, which is what tells a caller apart from a genuine ffmpeg failure.
command: Program and its arguments; no shell parsing is applied.options: Working directory and environment additions for the run.on_line: Called with each stdout line, without its newline.should_stop: Polled while the child runs; the first true terminates it.
Returns default process execution options.
Returns process options rooted in the supplied directory.
cwd: Directory the run happens in.
Returns the current subprocess tracker.
Whether a failure came from spawn_cancellable stopping the child rather than the child failing on its own.
failure: The error a checked run returned.
Closes the child's pipes and terminates and reaps it if still running. Register defer child.deinit() immediately after a successful spawn. A prior wait or pipe close is safe; repeated cleanup has no effect.
child: Child and its remaining pipes to release.
Returns a future that reaps the child and resolves to its exit code; signals are negative.
child: Child to reap; it may be waited on only once.
Sends the platform termination signal without consuming wait.
child: Child to signal;waitstill has to reap it.
Sends term, kill, int, or hup.
child: Child to signal.signal: One ofterm,kill,int, orhup.
Returns the process id, or -1 after reaping.
child: Child to identify.
Terminates the process with the supplied exit code.
code: Exit status for this process, taken modulo 256.
Returns the number of process arguments.
Runs a shell command and returns its exit code.
command: Command line handed to the platform shell.
Runs a shell command and returns output or an error value.
command: Command line handed to the platform shell.
Runs a shell command and captures its status and output.
command: Command line handed to the platform shell.
let shell = std.process.try_run("printf moon").unwrap()
println(shell.status)
println(shell.stdout)
let direct = std.process.run_args(["moon", "--version"])
println(direct.ok)
println(std.process.run_args_in(".", ["moon", "--version"]).code)
println(std.process.run_with_env("env", ["MOON_MODE=tour"]).stdout)Runs a shell command in the supplied working directory.
cwd: Directory to run in.command: Command line handed to the platform shell.
Runs an argv vector without shell parsing.
argv: Program and its arguments; no shell parsing is applied.
Runs an argv vector in the supplied working directory.
cwd: Directory to run in.argv: Program and its arguments; no shell parsing is applied.
Runs a shell command with explicit environment entries.
command: Command line handed to the platform shell.env: Environment entries spelled"KEY=VALUE".
Returns one process argument, or an empty string out of range.
index: Zero-based position among the process arguments.
println(std.process.program_name())
println(std.process.arg_count())
println(std.process.arg(0))
println(std.process.args())
println(std.process.args_after(1))Returns the process arguments.
Returns process arguments after the supplied index.
index: Zero-based position to start after.
Returns the invoked program name.