diff --git a/lib/shell.js b/lib/shell.js index 78712299..f5664705 100644 --- a/lib/shell.js +++ b/lib/shell.js @@ -53,22 +53,17 @@ class Shell { execStringCommand(command, options, { isExternal }) { return new Promise((resolve, reject) => { - sh.exec(command, { async: true }, (code, stdout, stderr) => { + const childProcess = sh.exec(command, { async: true }, (code, stdout, stderr) => { stdout = stdout.toString().trim(); - this.log.verbose(stdout, { isExternal }); debug({ command, options, code, stdout, stderr }); if (code === 0) { - if (stderr) { - this.log.verbose(stderr.toString().trim(), { isExternal }); - } resolve(stdout); } else { - if (stdout && stderr) { - this.log.log(`\n${stdout}`); - } reject(new Error(stderr || stdout)); } }); + childProcess.stdout.on('data', stdout => this.log.verbose(stdout.toString().trim(), { isExternal })); + childProcess.stderr.on('data', stderr => this.log.verbose(stderr.toString().trim(), { isExternal })); }); } diff --git a/test/shell.js b/test/shell.js index 6bcdf6d4..c4047b40 100644 --- a/test/shell.js +++ b/test/shell.js @@ -50,7 +50,9 @@ test('exec (verbose)', async t => { const shell = factory(Shell, { options: { verbose: true } }); const actual = await shell.exec('echo foo'); t.is(shell.log.exec.firstCall.args[0], 'echo foo'); + t.is(shell.log.exec.callCount, 1); t.is(shell.log.verbose.firstCall.args[0], 'foo'); + t.is(shell.log.verbose.callCount, 1); t.is(actual, 'foo'); });