diff options
Diffstat (limited to 'lib/utils/command.js')
-rw-r--r-- | lib/utils/command.js | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/lib/utils/command.js b/lib/utils/command.js index d2beba0..de240df 100644 --- a/lib/utils/command.js +++ b/lib/utils/command.js @@ -1,16 +1,10 @@ var _ = require('lodash'); var childProcess = require('child_process'); +var spawn = require("spawn-cmd").spawn; var Promise = require('./promise'); -// On borwser, command execution is not possible -var isAvailable = childProcess && childProcess.exec; - // Execute a command function exec(command, options) { - if (!isAvailable) { - return Promise.reject(new Error('Command execution is not possible on this platform')); - } - var d = Promise.defer(); var child = childProcess.exec(command, options, function(err, stdout, stderr) { @@ -34,18 +28,22 @@ function 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')); - } - +function spawnCmd(command, args, options) { var d = Promise.defer(); - var child = childProcess.spawn(command, args, options); + var child = spawn(command, args, options); child.on('error', function(error) { return d.reject(error); }); + child.stdout.on('data', function (data) { + d.notify(data); + }); + + child.stderr.on('data', function (data) { + d.notify(data); + }); + child.on('close', function(code) { if (code === 0) { d.resolve(); @@ -76,8 +74,7 @@ function optionsToShellArgs(options) { } module.exports = { - isAvailable: isAvailable, exec: exec, - spawn: spawn, + spawn: spawnCmd, optionsToShellArgs: optionsToShellArgs }; |