Created
March 19, 2023 01:37
-
-
Save epicfaace/edd3250371e0a984446129a013163c5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { spawn } from "child_process"; | |
import * as readline from "readline"; | |
const proc = spawn('node', ['/tmp/exec.js'], { stdio: 'pipe' }); | |
const readInterface = readline.createInterface({ input: proc.stdout }); | |
const readInterfaceStderr = readline.createInterface({ input: proc.stderr }); | |
await new Promise((resolve, reject) => { | |
readInterfaceStderr.on('line', (e: string) => { | |
console.error(e); | |
stderr += e + "\n"; | |
}); | |
readInterface.on('line', (e: string) => { | |
console.log(e); | |
stdout += e + "\n"; | |
}); | |
proc.on('exit', (code: number) => { | |
code === 0 ? resolve(stdout): reject(new Error(stderr)) | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment