MCPcopy
hub / github.com/CapSoftware/Cap / runCommand

Function runCommand

scripts/verify-recording-pipeline.mjs:107–220  ·  view source on GitHub ↗
(name, command, args, options = {})

Source from the content-addressed store, hash-verified

105}
106
107async function runCommand(name, command, args, options = {}) {
108 const cwd = options.cwd || root;
109 const env = { ...process.env, ...(options.env || {}) };
110 const timeoutMs =
111 options.timeoutMs ??
112 Number(process.env.CAP_VERIFY_COMMAND_TIMEOUT_MS || "180000");
113 const stdoutPath = outputPath(name, "stdout");
114 const stderrPath = outputPath(name, "stderr");
115 const statusPath = outputPath(name, "status.json");
116 const stdout = fs.createWriteStream(stdoutPath);
117 const stderr = fs.createWriteStream(stderrPath);
118 const startedAt = Date.now();
119
120 const result = await new Promise((resolve, reject) => {
121 const child = spawn(command, args, {
122 cwd,
123 env,
124 stdio: ["ignore", "pipe", "pipe"],
125 });
126
127 let stdoutText = "";
128 let stderrText = "";
129 let timedOut = false;
130 let killTimer = null;
131 const timeoutTimer =
132 timeoutMs > 0
133 ? setTimeout(() => {
134 timedOut = true;
135 child.kill("SIGTERM");
136 killTimer = setTimeout(() => child.kill("SIGKILL"), 5000);
137 }, timeoutMs)
138 : null;
139
140 child.stdout.on("data", (chunk) => {
141 const text = chunk.toString();
142 stdoutText += text;
143 stdout.write(chunk);
144 });
145
146 child.stderr.on("data", (chunk) => {
147 const text = chunk.toString();
148 stderrText += text;
149 stderr.write(chunk);
150 });
151
152 child.on("error", (error) => {
153 if (timeoutTimer) {
154 clearTimeout(timeoutTimer);
155 }
156 if (killTimer) {
157 clearTimeout(killTimer);
158 }
159 reject(error);
160 });
161 child.on("close", (code, signal) => {
162 if (timeoutTimer) {
163 clearTimeout(timeoutTimer);
164 }

Callers 12

buildCapFunction · 0.85
getTargetsFunction · 0.85
recordForegroundFunction · 0.85
recordDetachedFunction · 0.85
recordCameraMicFunction · 0.85
validateProjectFunction · 0.85
probeMediaFunction · 0.85
exportProjectFunction · 0.85
signDesktopAppIfNeededFunction · 0.85
openDeepLinkFunction · 0.85
launchDesktopAppFunction · 0.85

Calls 5

outputPathFunction · 0.85
rejectFunction · 0.85
onMethod · 0.80
writeMethod · 0.80
resolveFunction · 0.50

Tested by

no test coverage detected