Created
February 22, 2020 15:43
-
-
Save fabiojaniolima/2522cead03a68db307bd5af4c4e3d61e to your computer and use it in GitHub Desktop.
Returns a Promise that delegates to the operating system the execution of the instruction passed as a parameter
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
const { exec } = require('child_process') | |
/** | |
* It delegates to the operating system the execution of the instruction passed as a parameter | |
* @param {string} command Instruction to be executed on the operating system | |
* @returns {Promise} Resolves to an object: {success: [boolean], content: [string]} | |
*/ | |
const newProcess = command => { | |
return new Promise((resolve, reject) => { | |
exec(command, (_, stdout, stderr) => { | |
if (stdout) resolve({ success: true, content: stdout }) | |
reject({ success: false, content: stderr }) | |
}) | |
}) | |
} | |
module.exports = newProcess |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment