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

# 读取子进程的标准错误输出

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

```ts theme={null}
const proc = Bun.spawn(["echo", "hello"], {
  stderr: "pipe",
});

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

***

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

```ts theme={null}
const proc = Bun.spawn(["echo", "hello"], {
  stderr: "pipe",
});

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

***

参见 [子进程](/runtime/child-process)。
