Skip to content

使用 Bun.spawn() 时,子进程继承生成进程的 stderr。如果你想要读取和处理 stderr,请将 stderr 选项设置为 "pipe"

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

proc.stderr; // => ReadableStream

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

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

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

请参阅 文档 > API > 子进程 获取完整文档。

Bun学习网由www.bunjs.com.cn整理维护