From def096fbeabdbd490df05db10011fff189664402 Mon Sep 17 00:00:00 2001 From: Vrganj Date: Sat, 16 Jan 2021 01:03:49 +0100 Subject: [PATCH] Trim and subtring only after executing --- api/src/execute.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/api/src/execute.js b/api/src/execute.js index 3642671..1409a7b 100644 --- a/api/src/execute.js +++ b/api/src/execute.js @@ -34,11 +34,13 @@ async function execute(res, language, body) { result.output += chunk; }); - result.stderr = result.stderr.trim().substring(0, 65535); - result.stdout = result.stdout.trim().substring(0, 65535); - result.output = result.output.trim().substring(0, 65535); + process.on('exit', () => { + result.stderr = result.stderr.trim().substring(0, 65535); + result.stdout = result.stdout.trim().substring(0, 65535); + result.output = result.output.trim().substring(0, 65535); - process.on('exit', () => res.json(result)); + res.json(result); + }); } module.exports = {