std/process

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

Overview

Usage

import "std/process.zc"
import "std/io.zc"

fn main() {
    // Basic command execution
    let output = Command::new("echo")
        .arg("hello world")
        .output();
        
    if (output.exit_code == 0) {
        println(f"Captured: {output.std_out}");
        // output.std_out is a String, freed automatically
    } else {
        println(f"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.