std.process
Running other programs:
import std.process
let out = process.run("git", ["status", "--short"])?
if out.success() {
print(out.stdout)
} else {
eprint(out.stderr)
}The program is looked up in PATH unless the name contains a /. It gets no input and runs in the working directory; run waits until it has finished. Errors are messages such as cannot run "gti": not found.
Types
struct Output
pub struct Output {
pub code: i64,
pub stdout: string,
pub stderr: string,
}What a finished program wrote, and how it ended.
codeThe exit code: 0 for success, or 128 plus the number of the signal that stopped the program.
Methods
pub fn success(self) -> boolWhether the program exited with code 0.
Functions
fn run
pub fn run(cmd: string, args: List[string]) -> Result[Output, string]Runs cmd with args and waits for it. An exit code other than 0 is still Ok: check success() or code.
fn output
pub fn output(cmd: string, args: List[string]) -> Result[string, string]The standard output of cmd with args if it succeeds; otherwise an error with what it wrote to standard error.