sh

tcmts.dev.sh · #uw7hofgv · term · runs on the server

uses node:child_process

Run a program to the end: whether it passed, and what it printed.

import { spawnSync } from "node:child_process";

export function sh(program: string, args: string[], cwd: string, env: NodeJS.ProcessEnv = {}): { ok: boolean; out: string } {
  const r = spawnSync(program, args, { cwd, env: { ...process.env, NO_COLOR: "1", FORCE_COLOR: "0", ...env }, encoding: "utf8", maxBuffer: 1 << 28 });
  return { ok: r.status === 0, out: `${r.stdout ?? ""}${r.stderr ?? ""}${r.error ? String(r.error) : ""}` };
}

used by