openai/codex-action
Publicmirrored from https://github.com/openai/codex-actionAvailable
src/checkOutput.ts
27lines · modeblame
685900c1Michael Bolin8 months ago | 1 | import { spawn } from "child_process"; |
| 2 | | |
| 3 | export function checkOutput(command: Array<string>): Promise<string> { | |
| 4 | const [prog, ...args] = command; | |
| 5 | return new Promise<string>((resolve, reject) => { | |
| 6 | const proc = spawn(prog, args, { | |
| 7 | env: process.env, | |
| 8 | stdio: ["ignore", "pipe", "inherit"], | |
| 9 | }); | |
| 10 | | |
| 11 | proc.on("error", reject); | |
| 12 | | |
| 13 | let output = ""; | |
| 14 | proc.stdout.on("data", (chunk) => { | |
| 15 | output += chunk.toString(); | |
| 16 | }); | |
| 17 | | |
| 18 | proc.on("close", (code) => { | |
| 19 | if (code !== 0) { | |
| 20 | reject(new Error(`${prog} exited with code ${code}`)); | |
| 21 | return; | |
| 22 | } | |
| 23 | | |
| 24 | resolve(output); | |
| 25 | }); | |
| 26 | }); | |
| 27 | } |