Add stdin
This commit is contained in:
parent
8fd831982e
commit
c537cab2da
|
@ -39,6 +39,13 @@ app.post(
|
||||||
isArray: {
|
isArray: {
|
||||||
errorMessage: 'Supplied args is not an array',
|
errorMessage: 'Supplied args is not an array',
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
stdin: {
|
||||||
|
in: 'body',
|
||||||
|
optional: true,
|
||||||
|
isString: {
|
||||||
|
errorMessage: 'Supplied stdin is not a string',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
|
@ -49,7 +56,7 @@ app.post(
|
||||||
language.aliases.includes(req.body.language.toLowerCase())
|
language.aliases.includes(req.body.language.toLowerCase())
|
||||||
);
|
);
|
||||||
|
|
||||||
const { stdout, stderr, output, ran } = await execute(language, req.body.source, req.body.args);
|
const { stdout, stderr, output, ran } = await execute(language, req.body.source, req.body.args, req.body.stdin);
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
ran,
|
ran,
|
||||||
|
|
|
@ -26,7 +26,7 @@ const [languageName, sourceFile, ...args] = process.argv.slice(2);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { output } = await execute(language, source, args);
|
const { output } = await execute(language, source, '', args);
|
||||||
|
|
||||||
console.log(output);
|
console.log(output);
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -14,13 +14,15 @@ epoch=$(date +%s%N)
|
||||||
basepath="/var/lib/lxc/piston/rootfs"
|
basepath="/var/lib/lxc/piston/rootfs"
|
||||||
filepath="/tmp/$epoch/code.code"
|
filepath="/tmp/$epoch/code.code"
|
||||||
argpath="/tmp/$epoch/args.args"
|
argpath="/tmp/$epoch/args.args"
|
||||||
|
stdinpath="/tmp/$epoch/stdin.stdin"
|
||||||
arg=$(basename $argpath)
|
arg=$(basename $argpath)
|
||||||
|
|
||||||
# write arg file
|
# write arg file
|
||||||
mkdir -p $basepath/tmp/$epoch
|
mkdir -p $basepath/tmp/$epoch
|
||||||
chmod 777 $basepath/tmp/$epoch
|
chmod 777 $basepath/tmp/$epoch
|
||||||
cat $2 > $basepath$filepath
|
cat $2 > $basepath$filepath
|
||||||
echo "${@:3}" > $basepath$argpath
|
cat $3 > $basepath$argpath
|
||||||
|
echo "${@:4}" > $basepath$argpath
|
||||||
|
|
||||||
# process incrementor
|
# process incrementor
|
||||||
exec 200>$dir/lockfile
|
exec 200>$dir/lockfile
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
cd /tmp/$2
|
cd /tmp/$2
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 bash code.code"
|
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 bash code.code < stdin.stdin"
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
cd /tmp/$2
|
cd /tmp/$2
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 brainfuck code.code"
|
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 brainfuck code.code < stdin.stdin"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
runuser runner$1 -c "\
|
runuser runner$1 -c "\
|
||||||
cd /tmp/$2 ; \
|
cd /tmp/$2 ; \
|
||||||
gcc -std=c11 -o binary -x c code.code ; \
|
gcc -std=c11 -o binary -x c code.code ; \
|
||||||
cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary"
|
cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary < stdin.stdin"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
runuser runner$1 -c "\
|
runuser runner$1 -c "\
|
||||||
cd /tmp/$2 ; \
|
cd /tmp/$2 ; \
|
||||||
g++ -std=c++17 -o binary -x c++ code.code ; \
|
g++ -std=c++17 -o binary -x c++ code.code ; \
|
||||||
cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary"
|
cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary < stdin.stdin"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
runuser runner$1 -c "\
|
runuser runner$1 -c "\
|
||||||
cd /tmp/$2 ; \
|
cd /tmp/$2 ; \
|
||||||
mcs $(echo code.code | sed 's/\///') -nowarn:0219 -out:binary ; \
|
mcs $(echo code.code | sed 's/\///') -nowarn:0219 -out:binary ; \
|
||||||
cat args.args | xargs -d '\n' timeout -s KILL 3 mono binary"
|
cat args.args | xargs -d '\n' timeout -s KILL 3 mono binary < stdin.stdin"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
cd /tmp/$2
|
cd /tmp/$2
|
||||||
|
|
||||||
if [[ -z $(grep '[^[:space:]]' args.args) ]]; then
|
if [[ -z $(grep '[^[:space:]]' args.args) ]]; then
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; timeout -s KILL 3 deno run code.code"
|
runuser runner$1 -c "cd /tmp/$2 ; timeout -s KILL 3 deno run code.code < stdin.stdin"
|
||||||
else
|
else
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 deno run code.code"
|
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 deno run code.code < stdin.stdin"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -3,5 +3,5 @@ cd /tmp/$2
|
||||||
if [[ -z $(grep '[^[:space:]]' args.args) ]]; then
|
if [[ -z $(grep '[^[:space:]]' args.args) ]]; then
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; timeout -s KILL 3 elixir code.code"
|
runuser runner$1 -c "cd /tmp/$2 ; timeout -s KILL 3 elixir code.code"
|
||||||
else
|
else
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args ; xargs -d '\n' timeout -s KILL 3 elixir code.code"
|
runuser runner$1 -c "cd /tmp/$2 ; cat args.args ; xargs -d '\n' timeout -s KILL 3 elixir code.code < stdin.stdin"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -3,5 +3,5 @@ cd /tmp/$2
|
||||||
if [[ -z $(grep '[^[:space:]]' args.args) ]]; then
|
if [[ -z $(grep '[^[:space:]]' args.args) ]]; then
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; timeout -s KILL 3 emacs -Q --script code.code"
|
runuser runner$1 -c "cd /tmp/$2 ; timeout -s KILL 3 emacs -Q --script code.code"
|
||||||
else
|
else
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 emacs -Q --script code.code"
|
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 emacs -Q --script code.code < stdin.stdin"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -3,4 +3,4 @@ cp code.code interim.go
|
||||||
file="interim.go"
|
file="interim.go"
|
||||||
go build $file
|
go build $file
|
||||||
file=${file%%.*}
|
file=${file%%.*}
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ./$file"
|
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ./$file < stdin.stdin"
|
||||||
|
|
|
@ -4,4 +4,4 @@ mv code.code code.hs
|
||||||
runuser runner$1 -c "\
|
runuser runner$1 -c "\
|
||||||
cd /tmp/$2 ; \
|
cd /tmp/$2 ; \
|
||||||
ghc -dynamic -o binary code.hs > /dev/null 2>&1 ; \
|
ghc -dynamic -o binary code.hs > /dev/null 2>&1 ; \
|
||||||
cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary"
|
cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary < stdin.stdin"
|
||||||
|
|
|
@ -6,4 +6,4 @@ mv interim.java $name.java
|
||||||
runuser runner$1 -c "\
|
runuser runner$1 -c "\
|
||||||
cd /tmp/$2 ; \
|
cd /tmp/$2 ; \
|
||||||
javac $name.java ; \
|
javac $name.java ; \
|
||||||
cat args.args | xargs -d '\n' timeout -s KILL 3 java $name"
|
cat args.args | xargs -d '\n' timeout -s KILL 3 java $name < stdin.stdin"
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
cd /tmp/$2
|
cd /tmp/$2
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 jelly fu code.code"
|
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 jelly fu code.code < stdin.stdin"
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
cd /tmp/$2
|
cd /tmp/$2
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 julia code.code"
|
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 julia code.code < stdin.stdin"
|
||||||
|
|
|
@ -3,4 +3,4 @@ cp code.code code.kt
|
||||||
runuser runner$1 -c "\
|
runuser runner$1 -c "\
|
||||||
cd /tmp/$2 ; \
|
cd /tmp/$2 ; \
|
||||||
kotlinc code.kt -include-runtime -d code.jar ; \
|
kotlinc code.kt -include-runtime -d code.jar ; \
|
||||||
cat args.args | xargs -d '\n' timeout -s KILL 3 java -jar code.jar"
|
cat args.args | xargs -d '\n' timeout -s KILL 3 java -jar code.jar < stdin.stdin"
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
cd /tmp/$2
|
cd /tmp/$2
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 lua code.code"
|
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 lua code.code < stdin.stdin"
|
||||||
|
|
|
@ -2,4 +2,4 @@ runuser runner$1 -c "\
|
||||||
cd /tmp/$2 ; \
|
cd /tmp/$2 ; \
|
||||||
nasm -f elf32 -o binary.o code.code ; \
|
nasm -f elf32 -o binary.o code.code ; \
|
||||||
ld -m elf_i386 binary.o -o binary ; \
|
ld -m elf_i386 binary.o -o binary ; \
|
||||||
cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary"
|
cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary < stdin.stdin"
|
||||||
|
|
|
@ -2,4 +2,4 @@ runuser runner$1 -c "\
|
||||||
cd /tmp/$2 ; \
|
cd /tmp/$2 ; \
|
||||||
nasm -f elf64 -o binary.o code.code ; \
|
nasm -f elf64 -o binary.o code.code ; \
|
||||||
ld -m elf_x86_64 binary.o -o binary ; \
|
ld -m elf_x86_64 binary.o -o binary ; \
|
||||||
cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary"
|
cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary < stdin.stdin"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
cd /tmp/$2
|
cd /tmp/$2
|
||||||
|
|
||||||
if [[ -z $(grep '[^[:space:]]' args.args) ]]; then
|
if [[ -z $(grep '[^[:space:]]' args.args) ]]; then
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; timeout -s KILL 3 node code.code"
|
runuser runner$1 -c "cd /tmp/$2 ; timeout -s KILL 3 node code.code < stdin.stdin"
|
||||||
else
|
else
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 node code.code"
|
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 node code.code < stdin.stdin"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
cd /tmp/$2
|
cd /tmp/$2
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 perl code.code"
|
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 perl code.code < stdin.stdin"
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
cd /tmp/$2
|
cd /tmp/$2
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 php code.code"
|
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 php code.code < stdin.stdin"
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
cd /tmp/$2
|
cd /tmp/$2
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 python code.code"
|
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 python code.code < stdin.stdin"
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
cd /tmp/$2
|
cd /tmp/$2
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 python3.8 code.code"
|
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 python3.8 code.code < stdin.stdin"
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
cd /tmp/$2
|
cd /tmp/$2
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ruby code.code"
|
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 ruby code.code < stdin.stdin"
|
||||||
|
|
|
@ -2,4 +2,4 @@ cd /tmp/$2
|
||||||
rustc -o binary code.code
|
rustc -o binary code.code
|
||||||
runuser runner$1 -c "\
|
runuser runner$1 -c "\
|
||||||
cd /tmp/$2 ; \
|
cd /tmp/$2 ; \
|
||||||
cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary"
|
cat args.args | xargs -d '\n' timeout -s KILL 3 ./binary < stdin.stdin"
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
cd /tmp/$2
|
cd /tmp/$2
|
||||||
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 swift code.code"
|
runuser runner$1 -c "cd /tmp/$2 ; cat args.args | xargs -d '\n' timeout -s KILL 3 swift code.code < stdin.stdin"
|
||||||
|
|
|
@ -4,4 +4,4 @@ runuser runner$1 -c "\
|
||||||
tsc interim.ts ; \
|
tsc interim.ts ; \
|
||||||
rm -f interim.ts ; \
|
rm -f interim.ts ; \
|
||||||
mv interim.js code.code ; \
|
mv interim.js code.code ; \
|
||||||
cat args.args | xargs -d '\n' timeout -s KILL 3 node code.code"
|
cat args.args | xargs -d '\n' timeout -s KILL 3 node code.code < stdin.stdin"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const { writeFile } = require('fs/promises');
|
const { writeFile } = require('fs/promises');
|
||||||
const { spawn } = require('child_process');
|
const { spawn } = require('child_process');
|
||||||
|
|
||||||
function execute(language, source, args) {
|
function execute(language, source, args, stdin) {
|
||||||
return new Promise(async resolve => {
|
return new Promise(async resolve => {
|
||||||
const stamp = new Date().getTime();
|
const stamp = new Date().getTime();
|
||||||
const sourceFile = `/tmp/${stamp}.code`;
|
const sourceFile = `/tmp/${stamp}.code`;
|
||||||
|
@ -11,6 +11,7 @@ function execute(language, source, args) {
|
||||||
const process = spawn(__dirname + '/../lxc/execute', [
|
const process = spawn(__dirname + '/../lxc/execute', [
|
||||||
language.name,
|
language.name,
|
||||||
sourceFile,
|
sourceFile,
|
||||||
|
stdin ?? '',
|
||||||
args?.join('\n') ?? '',
|
args?.join('\n') ?? '',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue