Created
July 3, 2017 14:02
-
-
Save shuhrat/907390096f7d5333c85ea5ed41cf62e5 to your computer and use it in GitHub Desktop.
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
diff --git a/lib/utils.js b/lib/utils.js | |
index c90dd6b0..0c5ae37f 100644 | |
--- a/lib/utils.js | |
+++ b/lib/utils.js | |
@@ -6,7 +6,7 @@ | |
const assert = require('assert'); | |
const urlParse = require('url').parse; | |
const path = require('path'); | |
-const exec = require('child_process').exec; | |
+const processSpawn = require('child_process').spawn; | |
const _ = require('lodash'); | |
const Q = require('q'); | |
@@ -27,18 +27,30 @@ const debug = require('debug')('serp:q-utils'); | |
*/ | |
exports.execPromise = function(cmd, cwd) { | |
const defer = Q.defer(); | |
- const maxBuffer = 1024 * 1024; // 1Mb | |
+ const stdOut = []; | |
+ const stdErr = []; | |
debug(`executing: "${cmd}" in "${cwd}"`); | |
- exec(cmd, { cwd, maxBuffer }, (err, stdout, stderr) => { | |
- if (stderr) { | |
- debug(`>>> "${cmd}" stderr:`, stderr); | |
- } | |
- if (stdout) { | |
- debug(`>>> "${cmd}" stdout:`, stdout); | |
+ | |
+ processSpawn(cmd, { cwd }); | |
+ | |
+ processSpawn.stdout.on('data', (data) => { | |
+ debug(`>>> "${cmd}" stdout:`, data); | |
+ stdOut.push(data); | |
+ }); | |
+ | |
+ processSpawn.stderr.on('data', (data) => { | |
+ debug(`>>> "${cmd}" stderr:`, data); | |
+ stdErr.push(data); | |
+ }); | |
+ | |
+ processSpawn.on('close', (code) => { | |
+ debug(`child process exited with code ${code}`); | |
+ if (code !== 0) { | |
+ return defer.reject(stdErr.join('')); | |
} | |
- return err ? defer.reject(err) : defer.resolve(stdout); | |
+ defer.resolve(stdOut.join('')); | |
}); | |
return defer.promise; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment