Output both stderr and stdout

This commit is contained in:
1computer1 2019-06-15 20:08:03 -04:00
parent 6bf880a289
commit bc67dbbfd7
2 changed files with 8 additions and 13 deletions

View file

@ -29,13 +29,7 @@ class MessageInvalidListener extends Listener {
let errored = false; let errored = false;
let result; let result;
try { try {
const { stdout, stderr } = await this.client.languageHandler.evalCode(parse); ({ output: result, hasStderr: errored } = await this.client.languageHandler.evalCode(parse));
if (stderr) {
errored = true;
result = stderr;
} else {
result = stdout;
}
} catch (e) { } catch (e) {
errored = true; errored = true;
result = e.message; result = e.message;

View file

@ -155,15 +155,16 @@ class LanguageHandler extends AkairoHandler {
}, timeout); }, timeout);
} }
let stdout = ''; let output = '';
let stderr = ''; let hasStderr = false;
let error; let error;
proc.stdout.on('data', chunk => { proc.stdout.on('data', chunk => {
stdout += chunk; output += chunk;
}); });
proc.stderr.on('data', chunk => { proc.stderr.on('data', chunk => {
stderr += chunk; hasStderr = true;
output += chunk;
}); });
proc.on('error', e => { proc.on('error', e => {
@ -175,12 +176,12 @@ class LanguageHandler extends AkairoHandler {
handled = true; handled = true;
if (status !== 0 || error) { if (status !== 0 || error) {
if (!error) { if (!error) {
error = new Error(stderr || 'Something went wrong'); error = new Error(output || 'Something went wrong');
} }
reject(error); reject(error);
} else { } else {
resolve({ stdout, stderr }); resolve({ output, hasStderr });
} }
} }
}); });