MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / runCmd

Function runCmd

packages/kaos/test/cmd.test.ts:15–53  ·  view source on GitHub ↗

* Helper to run a cmd.exe command and collect stdout/stderr/exitCode. * Prepends `chcp 65001>nul &` to ensure UTF-8 output.

(
  kaos: Kaos,
  command: string,
)

Source from the content-addressed store, hash-verified

13 * Prepends `chcp 65001>nul &` to ensure UTF-8 output.
14 */
15async function runCmd(
16 kaos: Kaos,
17 command: string,
18): Promise<{ stdout: string; stderr: string; exitCode: number }> {
19 const proc: KaosProcess = await kaos.exec('cmd.exe', '/c', `chcp 65001>nul & ${command}`);
20
21 proc.stdin.end();
22
23 const stdoutChunks: Buffer[] = [];
24 const stderrChunks: Buffer[] = [];
25
26 const stdoutDone = new Promise<void>((resolve) => {
27 proc.stdout.on('data', (chunk: Buffer) => {
28 stdoutChunks.push(chunk);
29 });
30 proc.stdout.on('end', () => {
31 resolve();
32 });
33 });
34
35 const stderrDone = new Promise<void>((resolve) => {
36 proc.stderr.on('data', (chunk: Buffer) => {
37 stderrChunks.push(chunk);
38 });
39 proc.stderr.on('end', () => {
40 resolve();
41 });
42 });
43
44 const exitCode = await proc.wait();
45 await stdoutDone;
46 await stderrDone;
47
48 return {
49 stdout: Buffer.concat(stdoutChunks).toString('utf-8'),
50 stderr: Buffer.concat(stderrChunks).toString('utf-8'),
51 exitCode,
52 };
53}
54
55describe.skipIf(process.platform !== 'win32')('LocalKaos cmd.exe', () => {
56 let kaos: Kaos;

Callers 1

cmd.test.tsFile · 0.85

Calls 7

execMethod · 0.65
onMethod · 0.65
waitMethod · 0.65
toStringMethod · 0.65
resolveFunction · 0.50
endMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected