Every feature of command-stream, with executable JavaScript and Rust examples, captured output, and the same thing written with other shell libraries.
This file is generated by node scripts/generate-docs.mjs. Edit the examples in
js/examples/features/ or the catalog in js/examples/features/catalog.mjs instead.
All 25 examples were executed in JavaScript and Rust. JavaScript was checked in Node.js and Bun.
| Feature | JavaScript (Node.js) | JavaScript (Bun) | Rust |
|---|---|---|---|
| Await a command | ✓ | ✓ | ✓ |
| Read the output with text() | ✓ | ✓ | ✓ |
| Synchronous execution | ✓ | ✓ | ✓ |
| Exit codes and errors | ✓ | ✓ | ✓ |
| Options: capture, cwd, env, stdin | ✓ | ✓ | ✓ |
| Function and builder APIs | ✓ | ✓ | ✓ |
| Killing and cancelling commands | ✓ | ✓ | ✓ |
| Async iteration over output | ✓ | ✓ | ✓ |
| Event-driven output | ✓ | ✓ | ✓ |
| Writing to stdin while a command runs | ✓ | ✓ | ✓ |
| Buffer and string interfaces | ✓ | ✓ | ✓ |
| Mirroring and capturing output | ✓ | ✓ | ✓ |
| The built-in command catalog | ✓ | ✓ | ✓ |
| File system built-ins | ✓ | ✓ | ✓ |
| Text and value built-ins | ✓ | ✓ | ✓ |
| Environment built-ins | ✓ | ✓ | ✓ |
| Registering your own commands | ✓ | ✓ | ✓ |
| The handler context | ✓ | ✓ | ✓ |
| Streaming commands | ✓ | ✓ | ✓ |
| Pipelines | ✓ | ✓ | ✓ |
| Redirecting output and input | ✓ | ✓ | ✓ |
| Command sequences | ✓ | ✓ | ✓ |
| Safe interpolation | ✓ | ✓ | ✓ |
| Shell settings | ✓ | ✓ | ✓ |
| ANSI and control character helpers | ✓ | ✓ | ✓ |
✓ supported, — not supported. Follow a feature for the code in each library.
| Feature | command-stream | Bun.$ | zx | execa | ShellJS | node:child_process |
|---|---|---|---|---|---|---|
| Await a command | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Read the output with text() | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Synchronous execution | ✓ | — | ✓ | ✓ | ✓ | ✓ |
| Exit codes and errors | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Options: capture, cwd, env, stdin | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Function and builder APIs | ✓ | — | ✓ | ✓ | ✓ | ✓ |
| Killing and cancelling commands | ✓ | — | ✓ | ✓ | ✓ | ✓ |
| Async iteration over output | ✓ | ✓ | ✓ | ✓ | — | ✓ |
| Event-driven output | ✓ | — | ✓ | ✓ | ✓ | ✓ |
| Writing to stdin while a command runs | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Buffer and string interfaces | ✓ | ✓ | ✓ | ✓ | — | ✓ |
| Mirroring and capturing output | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| The built-in command catalog | ✓ | ✓ | — | — | ✓ | — |
| File system built-ins | ✓ | ✓ | ✓ | — | ✓ | — |
| Text and value built-ins | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Environment built-ins | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Registering your own commands | ✓ | — | — | — | ✓ | — |
| The handler context | ✓ | — | — | — | ✓ | — |
| Streaming commands | ✓ | — | — | — | — | — |
| Pipelines | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Redirecting output and input | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Command sequences | ✓ | ✓ | ✓ | — | ✓ | ✓ |
| Safe interpolation | ✓ | ✓ | ✓ | ✓ | — | ✓ |
| Shell settings | ✓ | ✓ | ✓ | — | ✓ | ✓ |
| ANSI and control character helpers | ✓ | — | ✓ | ✓ | — | — |
- Await a command — Awaiting a command returns an object with stdout, stderr and the exit code.
- Synchronous execution — The same command can be run without awaiting, blocking until it finishes.
- Exit codes and errors — A non-zero exit code is reported on the result instead of thrown, unless errexit is set.
- Options: capture, cwd, env, stdin — Execution options control capture, cwd, environment and stdin for a command or reusable runner.
- Function and builder APIs — Commands can also be built from plain strings instead of template literals.
- Killing and cancelling commands — A running command can be killed, and cancelling one leaves the rest of the script running.
- Read the output with text() — Captured stdout is available as text through each language’s result API.
- Buffer and string interfaces — Output is available as a string and as raw bytes, without running the command twice.
- Mirroring and capturing output — Output can be shown, captured, both or neither, chosen independently.
- Async iteration over output — A command is an async iterable of chunks, so output can be handled as it arrives.
- Event-driven output — Event APIs report output and lifecycle signals as work progresses.
- Writing to stdin while a command runs — Input can be supplied up front or written to a running command.
- The built-in command catalog — Common commands are implemented in-process in both languages for portable behavior.
- File system built-ins — ls, cat, mkdir, touch, cp, mv, rm and test run in-process.
- Text and value built-ins — echo, seq, yes, basename, dirname, true and false run in-process.
- Environment built-ins — cd, pwd, env, which and exit affect the command they run in, not the host process.
- Registering your own commands — A handler can be registered by name and invoked through a registry or command runner.
- The handler context — A handler receives args, stdin, cwd, env and a cancellation signal.
- Streaming commands — A streaming handler publishes output incrementally like a real process.
- Pipelines — Commands can be composed into pipelines whose output feeds the next stage.
- Redirecting output and input — >, >> and < redirect command input and output with shell-compatible behavior.
- Command sequences — &&, ||, ; and parentheses execute with the expected shell semantics.
- Safe interpolation — Interpolated values are escaped as arguments; each language also exposes an explicit raw form.
- Shell settings — Shell settings model errexit, pipefail, verbose, xtrace and nounset behavior.
- ANSI and control character helpers — Helpers can strip colours and control characters from captured output.
| Library | Version | Runs in |
|---|---|---|
| command-stream | this repository | Node.js, Bun |
| Bun.$ | 1.4 | Bun |
| zx | 8 | Node.js, Bun, Deno |
| execa | 9.6 | Node.js, Bun, Deno |
| ShellJS | 0.10 | Node.js, Bun |
| node:child_process | this repository | Node.js, Bun, Deno |