Skip to content

Instantly share code, notes, and snippets.

@superjojo140
Created December 16, 2020 14:02
Show Gist options
  • Save superjojo140/1acb3bfbea147a405d6ed134cf21d3bc to your computer and use it in GitHub Desktop.
Save superjojo140/1acb3bfbea147a405d6ed134cf21d3bc to your computer and use it in GitHub Desktop.
[Node] Executes a shell command as Promise.
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