-
-
Save danyelhenrique/6fc68e9eafccc0047912c366d89fb675 to your computer and use it in GitHub Desktop.
nodejs spawn promisse async
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
| #!/usr/bin/env node | |
| /** | |
| * @param {string} command process to run | |
| * @param {string[]} args command line arguments | |
| * @returns {Promise<void>} promise | |
| */ | |
| const runCommand = (command, args) => { | |
| const cp = require("child_process"); | |
| return new Promise((resolve, reject) => { | |
| const executedCommand = cp.spawn(command, args, { | |
| stdio: "inherit", | |
| shell: true | |
| }); | |
| executedCommand.on("error", error => { | |
| reject(error); | |
| }); | |
| executedCommand.on("exit", code => { | |
| if (code === 0) { | |
| resolve(); | |
| } else { | |
| reject(); | |
| } | |
| }); | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment