> ## Documentation Index
> Fetch the complete documentation index at: https://bun.zhcndoc.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 从子进程读取 stderr

使用 [`Bun.spawn()`](/runtime/child-process) 时，子进程会继承父进程的 `stderr`。如果你想读取并处理 `stderr`，请将 `stderr` 选项设置为 `"pipe"`。

```ts theme={"theme":{"light":"github-light","dark":"dracula"}}
const proc = Bun.spawn(["echo", "hello"], {
  stderr: "pipe",
});

proc.stderr; // => ReadableStream
```

***

要读取 `stderr` 直到子进程退出，可以使用 `.text()`

```ts theme={"theme":{"light":"github-light","dark":"dracula"}}
const proc = Bun.spawn(["echo", "hello"], {
  stderr: "pipe",
});

const errors: string = await proc.stderr.text();
if (errors) {
  // 处理错误
}
```

***

完整文档请参见 [文档 > API > 子进程](/runtime/child-process)。
