A module for spawning and managing system processes.
test {
// Example: Running a simple command and capturing output
let output = try {
Command::new("moon")
.arg("version")
.stdout(Piped) // Capture stdout
.output()
} catch {
e => abort("Failed to execute process: \{e}")
}
if output.status.success() {
println("Command succeeded!")
// Access output.stdout
}
}test {
// Example: Writing to stdin and reading from stdout
// Note: "grep" needs to be available in your PATH (use "findstr" on Windows)
let child = Command::new("grep")
.arg("hello")
.stdin(Piped)
.stdout(Piped)
.spawn()
// Write to stdin
let input = @utf8.encode("hello world\ngoodbye\n")
let _ = child.write_stdin(input)
child.close_stdin() // Signal EOF
// Read from stdout
let buf = Bytes::make(1024, b'\x00')
let n = child.read_stdout(buf)
if n > 0 {
let _out_str = @utf8.decode(buf) // "hello world\n"
()
}
let _ = child.wait()
}pub suberror ProcessError {
NotFound(String)
PermissionDenied(String)
Unknown(String)
}pub(all) struct Child {
pid : Int
handle : Int64
stdin : Int64
stdout : Int64
stderr : Int64
}pub struct ExitStatus {
exit_code : Int
}impl Eq for ExitStatusimpl Show for ExitStatusInstall
Download zipA module for spawning and managing system processes.