runStreaming
uses node:child_process
Like run, but hands output to a callback as it arrives (for running on behalf of a remote client).
import { nodeArgs, writeRunner } from "#codebase/tcmts/loader"; import type { DefSource, Layout } from "#codebase/tcmts/loader"; import { spawn } from "node:child_process"; export function runStreaming( hash: string, args: string[], src: DefSource, lay: Layout, onOutput: (stream: "stdout" | "stderr", data: string) => void, ): Promise<number> { const child = spawn(process.execPath, [...nodeArgs(lay), writeRunner(hash, src, lay), ...args], { stdio: ["ignore", "pipe", "pipe"] }); child.stdout.setEncoding("utf8").on("data", (d: string) => onOutput("stdout", d)); child.stderr.setEncoding("utf8").on("data", (d: string) => onOutput("stderr", d)); return new Promise((resolve) => child.on("close", (code) => resolve(code ?? 1))); }