使用 Bun.spawn() 时,子进程的 stdout 可以通过 proc.stdout 作为 ReadableStream 消费。
ts
const proc = Bun.spawn(["echo", "hello"]);
const output = await proc.stdout.text();
output; // => "hello"要将子进程的 stdout 管道传输到父进程的 stdout,请设置为 "inherit"。
ts
const proc = Bun.spawn(["echo", "hello"], {
stdout: "inherit",
});请参阅 文档 > API > 子进程 获取完整文档。