Skip to content

Instantly share code, notes, and snippets.

@fabiojaniolima
Created February 22, 2020 15:43
Show Gist options
  • Save fabiojaniolima/2522cead03a68db307bd5af4c4e3d61e to your computer and use it in GitHub Desktop.
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
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