[Runtime
](../../../index.md)[Package Manager
](../../../pm/cli/install/index.md)[Bundler
](../../../bundler/index.md)[Test Runner
](../../../test/index.md)[Guides
](../../index.md)[Reference
](https://bun.com/reference)[Blog
](https://bun.com/blog)[Feedback
](../../../feedback/index.md)
Use Bun.spawn() to spawn a child process.
const proc = Bun.spawn(["echo", "hello"]);
// await completion
await proc.exited;
The second argument accepts a configuration object.
const proc = Bun.spawn(["echo", "Hello, world!"], {
cwd: "/tmp",
env: { FOO: "bar" },
onExit(proc, exitCode, signalCode, error) {
// exit handler
},
});
By default, the stdout of the child process can be consumed as a ReadableStream using proc.stdout.
const proc = Bun.spawn(["echo", "hello"]);
const output = await proc.stdout.text();
output; // => "hello\n"
See Docs > API > Child processes for complete documentation.
Was this page helpful?
[
Enable compression for WebSocket messages
Previous
](../../websocket/compression/index.md)[
Read stdout from a child process
Next
](../spawn-stdout/index.md)