Skip to content

Instantly share code, notes, and snippets.

@epicfaace
Created March 19, 2023 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epicfaace/edd3250371e0a984446129a013163c5f to your computer and use it in GitHub Desktop.
Save epicfaace/edd3250371e0a984446129a013163c5f to your computer and use it in GitHub Desktop.
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