Run subprocesses and access process utilities:
import process
let result = process.run(["ls", "-la"], cwd="/tmp")
print(result.stdout())
let out = process.cmd("echo").arg("hello").capture()
let cwd = process.getcwd()
let args = process.argv()
| Function | Returns | Description |
|---|---|---|
process.run(args, cwd?, env?) | ProcessResult | Run a subprocess |
process.cmd(program) | Command | Create a fluent command builder |
process.getcwd() | Str | Return current working directory |
process.realpath(p) | Str | Return canonical path, resolving symlinks |
process.tempdir() | Str | Return system temporary directory |
process.exit(code) | None | Exit with status code |
process.argv() | List[Str] | Return command-line arguments |
ProcessResult methods:
| Method | Returns | Description |
|---|---|---|
.exit_code() | Int | Process exit code |
.stdout() | Str | Captured standard output |
.stderr() | Str | Captured standard error |
.ok() | Bool | True if exit code is 0 |
.require_ok() | ProcessResult | Returns self or throws if exit code is non-zero |
Command builder methods:
| Method | Returns | Description |
|---|---|---|
.arg(value) | Command | Append a single argument |
.args(values) | Command | Append multiple arguments |
.with_cwd(path) | Command | Set working directory |
.with_env(name, value) | Command | Set environment variable |
.run() | ProcessResult | Execute and return result |
.check() | ProcessResult | Execute and throw if non-zero exit |
.capture() | Str | Execute and return stdout (throws if non-zero exit) |