UNPKG

bun-types

Version:

Type definitions and documentation for Bun, an incredibly fast JavaScript runtime

44 lines (31 loc) 817 B
--- title: Spawn a child process sidebarTitle: Spawn child process mode: center --- Use [`Bun.spawn()`](/docs/runtime/child-process) to spawn a child process. ```ts const proc = Bun.spawn(["echo", "hello"]); // await completion await proc.exited; ``` --- The second argument accepts a configuration object. ```ts 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`. ```ts const proc = Bun.spawn(["echo", "hello"]); const output = await proc.stdout.text(); output; // => "hello\n" ``` --- See [Docs > API > Child processes](/docs/runtime/child-process) for complete documentation.