Bun

指南进程

使用 Bun 从子进程读取 stdout

使用 Bun.spawn() 时,子进程的 stdout 可以通过 proc.stdout 作为 ReadableStream 进行消耗。

const proc = Bun.spawn(["echo", "hello"]);

const output = await proc.stdout.text();
output; // => "hello"

要将子进程的 stdout 管道传输到父进程的 stdout,请将值设置为 "inherit"。

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

有关完整文档,请参阅 文档 > API > 子进程