Files
bun.sh/docs/guides/process/spawn-stderr.mdx
2025-11-05 11:14:21 -08:00

35 lines
744 B
Plaintext

---
title: Read stderr from a child process
sidebarTitle: Read stderr
mode: center
---
When using [`Bun.spawn()`](https://bun.com/docs/api/spawn), the child process inherits the `stderr` of the spawning process. If instead you'd prefer to read and handle `stderr`, set the `stderr` option to `"pipe"`.
```ts
const proc = Bun.spawn(["echo", "hello"], {
stderr: "pipe",
});
proc.stderr; // => ReadableStream
```
---
To read `stderr` until the child process exits, use .text()
```ts
const proc = Bun.spawn(["echo", "hello"], {
stderr: "pipe",
});
const errors: string = await proc.stderr.text();
if (errors) {
// handle errors
}
```
---
See [Docs > API > Child processes](https://bun.com/docs/api/spawn) for complete documentation.