std/process

March 14, 2026 ยท View on GitHub

The std/process module provides a high-level API for spawning child processes, executing system commands, and capturing their output.

Overview

  • Builder Pattern: The Command struct uses a fluid builder pattern for constructing command lines.
  • Output Capture: Easily capture standard output and exit codes from finished processes.
  • RAII: Both Command and Output implement the Drop trait for automatic cleanup of internal buffers.
  • Standard Interop: Seamlessly wraps underlying system-level process manipulation.

Usage

import "std/process.zc"

fn main() {
    // Basic command execution
    let output = Command::new("echo")
        .arg("hello world")
        .output();
        
    if (output.exit_code == 0) {
        println "Captured: {output.std_out}";
        // output.std_out is a String, freed automatically
    } else {
        println "Command failed with code {output.exit_code}";
    }
}

Struct Definitions

Command

A builder for configuring and spawning a process.

struct Command {
    program: String;
    args: Vec<String>;
}

Output

The result of a completed process execution.

struct Output {
    std_out: String;
    exit_code: int;
}

Methods

Command Methods

MethodSignatureDescription
newCommand::new(program: char*) -> CommandCreates a new Command for the given program.
argarg(self, arg: char*) -> Command*Adds an argument and returns a pointer to self for chaining.
outputoutput(self) -> OutputExecutes the command and waits for completion, capturing stdout.
statusstatus(self) -> intExecutes the command and returns the exit status code.

Memory Management

MethodSignatureDescription
freefree(self)Manually frees internal command buffers.
Traitimpl Drop for CommandAutomatically cleans up command buffers.
Traitimpl Drop for OutputAutomatically frees the captured output string.