std.process
Starts child processes and talks to them. A Command says what to start, Command.spawn starts it as a Child — its standard streams pipes (PipeReader, PipeWriter) where the command asked for them —, and Child.wait waits for its end as an ExitStatus; Command.output and Command.status do it all at once.
A child's end comes as SIGCHLD, which the runtime keeps for itself: a reaper on a thread of its own asks each child that has not been seen to end (lyr/process.h), and an end wakes every task that waits for it, on any thread. Waiting is a point of cancellation: a cancel ends it. On Windows a child is its process handle, its end wakes the reaper from a registered wait, and a kill is the only signal there is.
Examples
Compiles; not run here
import std.io { println };
import std.process { Command };
fn main(): void throws Error {
let run = Command { program = "git", args = ["--version"], stdout = .Piped };
let out = try run.output();
println(out.status.success());
}
Types
Stdio enum — What a child's standard stream is connected to: the parent's, a pipe to the parent, or nothing.
Command struct — Describes a process to start: the program — a path, or a name looked up on PATH —, its arguments, its working directory (the parent's where
null), variables set over the parent's environment, and its three standard streams.Child class — A started child process: its standard streams where the command piped them, waiting for its end, and signalling it.
ExitStatus struct — How a child ended: with an exit code — 0 to 255 on POSIX, any 32 bits on Windows —, or, on POSIX, by a signal.
Output struct — The result of Command.output: how the child ended, and all it wrote on its two streams.
PipeReader class — The parent's end of a child's output or error pipe: a
Reader that waits until bytes come, and returns 0 once the child has closed its end.PipeWriter class — The parent's end of a child's input pipe: a
Writer that waits until the pipe takes some; writing after the child has closed its end throws BrokenPipe.