Created
November 18, 2021 10:09
-
-
Save aztack/f863296696c77eae261479eabf454ceb to your computer and use it in GitHub Desktop.
wrap child_process.exec
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
/** | |
/** | |
* Essentially wraps `child_process.exec` into a promise. | |
* | |
* @param script Command line to run as a shell command. | |
*/ | |
function run(script) { | |
return new Promise((resolve, reject) => { | |
const env = Object.assign({}, process.env); | |
const scriptProcess = cp.exec(script, { | |
cwd: process.cwd(), | |
env, | |
}); | |
scriptProcess.stdout.pipe(process.stdout); | |
scriptProcess.stderr.pipe(process.stderr); | |
scriptProcess.on('error', reject); | |
scriptProcess.on('close', resolve); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment