从子进程读取 stderr
当你使用 Bun.spawn() 创建子进程时,它会继承生成该子进程的进程的 stderr。要改为读取并处理 stderr,请将 stderr 选项设置为 "pipe"。
TypeScript
const proc = Bun.spawn(["echo", "hello"], {
stderr: "pipe",
});
proc.stderr; // => ReadableStream
要读取 stderr,直到子进程退出,请使用 .text()。
TypeScript
const proc = Bun.spawn(["echo", "hello"], {
stderr: "pipe",
});
const errors: string = await proc.stderr.text();
if (errors) {
// 处理错误
}
参见子进程。