Bun

指南程序

使用 Bun 讀取子程序的 stderr

當使用 Bun.spawn() 時,子程序會繼承父程序的 stderr。如果你希望讀取和處理 stderr,請將 stderr 選項設定為 "pipe"

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

要讀取 stderr 直到子程序退出,請使用 .text()

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

const errors: string = await proc.stderr.text();
if (errors) {
  // handle errors
}

有關完整文件,請參閱 文件 > API > 子程序