Make execute.js support older Node versions

This commit is contained in:
Vrganj 2021-01-17 01:12:13 +00:00
parent 008d55643b
commit e637a95b33
1 changed files with 6 additions and 6 deletions

View File

@ -1,18 +1,18 @@
const { writeFile } = require('fs/promises');
const { writeFileSync } = require('fs');
const { spawn } = require('child_process');
function execute(language, source, stdin, args) {
return new Promise(async resolve => {
function execute(language, source, stdin = '', args = []) {
return new Promise(resolve => {
const stamp = new Date().getTime();
const sourceFile = `/tmp/${stamp}.code`;
await writeFile(sourceFile, source);
writeFileSync(sourceFile, source);
const process = spawn(__dirname + '/../lxc/execute', [
language.name,
sourceFile,
stdin ?? '',
args?.join('\n') ?? '',
stdin,
args.join('\n'),
]);
let stdout = '';