Merge branch 'master' of ssh://github.com/engineer-man/piston

This commit is contained in:
Brian Seymour 2021-01-23 14:15:03 -06:00
commit 6db1688a37
1 changed files with 9 additions and 3 deletions

View File

@ -1,6 +1,8 @@
const { writeFileSync, unlinkSync } = require('fs'); const { writeFileSync, unlinkSync } = require('fs');
const { spawn } = require('child_process'); const { spawn } = require('child_process');
const OUTPUT_LIMIT = 65535;
function execute(language, source, stdin = '', args = []) { function execute(language, source, stdin = '', args = []) {
return new Promise(resolve => { return new Promise(resolve => {
const stamp = new Date().getTime(); const stamp = new Date().getTime();
@ -20,11 +22,15 @@ function execute(language, source, stdin = '', args = []) {
let output = ''; let output = '';
process.stderr.on('data', chunk => { process.stderr.on('data', chunk => {
if (stderr.length >= OUTPUT_LIMIT) return;
stderr += chunk; stderr += chunk;
output += chunk; output += chunk;
}); });
process.stdout.on('data', chunk => { process.stdout.on('data', chunk => {
if (stdout.length >= OUTPUT_LIMIT) return;
stdout += chunk; stdout += chunk;
output += chunk; output += chunk;
}); });
@ -32,9 +38,9 @@ function execute(language, source, stdin = '', args = []) {
process.on('exit', code => { process.on('exit', code => {
unlinkSync(sourceFile); unlinkSync(sourceFile);
stderr = stderr.trim().substring(0, 65535); stderr = stderr.trim().substring(0, OUTPUT_LIMIT);
stdout = stdout.trim().substring(0, 65535); stdout = stdout.trim().substring(0, OUTPUT_LIMIT);
output = output.trim().substring(0, 65535); output = output.trim().substring(0, OUTPUT_LIMIT);
resolve({ resolve({
stdout, stdout,