使用 Bun.spawn()
時,子程序的 stdout
可以透過 proc.stdout
作為 ReadableStream
使用。
const proc = Bun.spawn(["echo", "hello"]);
const output = await new Response(proc.stdout).text();
output; // => "hello"
若要將子程序的 stdout
導向父程序的 stdout
,請設定「inherit」。
const proc = Bun.spawn(["echo", "hello"], {
stdout: "inherit",
});
請參閱 文件 > API > 子程序 以取得完整的說明文件。