blob: 9e9e8da99be30e306d6a8a2667dbc77849dc6341 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
---
name: Read stderr from a child process
---
When using [`Bun.spawn()`](/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 the [`Bun.readableStreamToText()`](/docs/api/utils#bun-readablestreamto) convenience function.
```ts
const proc = Bun.spawn(["echo", "hello"], {
stderr: "pipe",
});
const errors: string = await Bun.readableStreamToText(proc.stderr);
if (errors) {
// handle errors
}
```
---
See [Docs > API > Child processes](/docs/api/spawn) for complete documentation.
|