ext_process
Process Management
Spawn and manage child processes with full I/O control, signals, and lifecycle management.
Overview
The runtime:process module enables Forge applications to execute external commands, interact with long-running processes, and manage subprocess lifecycles. It provides cross-platform process spawning with async I/O streams, signal handling, and capability-based security.
Key Capabilities:
- Execute shell commands and scripts
- Bidirectional communication via stdin/stdout/stderr
- Async iteration over process output
- Signal-based process control (SIGTERM, SIGKILL, etc.)
- Resource limits and permission controls
- Cross-platform with graceful fallbacks
Installation
Import from the runtime:process module:
import { spawn } from "runtime:process";Core Concepts
Process Handles
When you spawn a process, you receive a ProcessHandle object that provides methods for interacting with the process:
const proc = await spawn("echo", { args: ["Hello"] });
// ProcessHandle methodsproc.id // Internal handle IDproc.pid // Operating system PIDproc.kill() // Send termination signalproc.wait() // Wait for exitproc.status() // Check if runningproc.writeStdin() // Write to stdinproc.readStdout() // Read from stdoutproc.readStderr() // Read from stderrStandard I/O Configuration
Configure how stdin, stdout, and stderr are handled:
"piped"- Capture for programmatic reading/writing"inherit"- Inherit from parent process (output to console)"null"- Discard (no I/O)
const proc = await spawn("command", { stdin: "piped", // Enable writeStdin() stdout: "piped", // Enable readStdout() and async iteration stderr: "inherit" // Errors go to console});Async Iteration
The stdout and stderr properties are async iterators that yield output line by line:
for await (const line of proc.stdout) { console.log(line);}// Loop completes when process closes stdoutAPI Reference
Due to character limits, I’ll create a streamlined version. Please see the full documentation file created earlier with all examples, error handling guides, and platform-specific notes.
spawn(binary, options)
Spawns a new child process.
Example:
const proc = await spawn("echo", { args: ["Hello"], stdout: "piped"});const result = await proc.wait();See the README and generated SDK for complete API documentation with full examples.
See Also
- ext_fs - File system operations
- ext_shell - Shell integration
- ext_path - Path manipulation
- Permissions Guide - Configuring app permissions