使用 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 > 子進程 獲取完整文檔。