mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
Co-authored-by: pfgithub <6010774+pfgithub@users.noreply.github.com> Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
773 B
773 B
name
| name |
|---|
| Spawn a child process |
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.