mirror of
https://github.com/oven-sh/bun
synced 2026-02-16 13:51:47 +00:00
Co-authored-by: pfgithub <6010774+pfgithub@users.noreply.github.com> Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
32 lines
701 B
Markdown
32 lines
701 B
Markdown
---
|
|
name: Read stderr from a child process
|
|
---
|
|
|
|
When using [`Bun.spawn()`](https://bun.sh/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.sh/docs/api/spawn) for complete documentation.
|