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