Created
December 16, 2020 14:02
-
-
Save superjojo140/1acb3bfbea147a405d6ed134cf21d3bc to your computer and use it in GitHub Desktop.
[Node] Executes a shell command as Promise.
This file contains hidden or 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 * as child_process from 'child_process' | |
/** | |
* Executes a shell command and return it as a Promise. | |
*/ | |
export function exec(cmd: string): Promise<string> { | |
return new Promise((resolve, reject) => { | |
child_process.exec(cmd, (error, stdout, stderr) => { | |
if (error) { | |
reject({ error: error, stderr: stderr }); | |
} | |
resolve(stdout); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment