Bun.spawn() in Bun
From the Bun cheat sheet ยท Shell & Child Processes ยท verified Jul 2026
Bun.spawn()
Spawn child processes with fine-grained control
typescript
// Run a command
const proc = Bun.spawn(["echo", "Hello"]);
await proc.exited; // Wait for completion
// Capture stdout
const proc = Bun.spawn(["ls", "-la"], {
stdout: "pipe",
});
const output = await new Response(proc.stdout).text();๐ก Bun.spawn() takes an array of args โ no shell interpretation, safe from injection
โก Use Bun.spawnSync() for quick blocking commands like git status
๐ Set stdout: "pipe" to capture output โ then read it as a Response stream
๐ข Prefer Bun.$ for simple commands and Bun.spawn() for fine-grained process control
spawnprocesschild