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