* 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, )
| 13 | * Prepends `chcp 65001>nul &` to ensure UTF-8 output. |
| 14 | */ |
| 15 | async 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 | |
| 55 | describe.skipIf(process.platform !== 'win32')('LocalKaos cmd.exe', () => { |
| 56 | let kaos: Kaos; |