diff options
Diffstat (limited to 'lib/utils/command.js')
-rw-r--r-- | lib/utils/command.js | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/lib/utils/command.js b/lib/utils/command.js index f395fa1..4269d6c 100644 --- a/lib/utils/command.js +++ b/lib/utils/command.js @@ -13,7 +13,32 @@ function exec(command, options) { return Promise.nfcall(childProcess.exec, command, options); } +// Spawn an executable +function spawn(command, args, options) { + if (!isAvailable) { + return Promise.reject(new Error('Command execution is not possible on this platform')); + } + + var d = Promise.deferred(); + var child = childProcess.spawn(command, args, options); + + child.on('error', function(error) { + return d.reject(error); + }); + + child.on('close', function(code) { + if (code === 0) { + d.resolve(); + } else { + d.reject(new Error('Error with command "'+command+'"')); + } + }); + + return d.promise; +} + module.exports = { isAvailable: isAvailable, - exec: exec + exec: exec, + spawn: spawn }; |