add support for multiple arguments
This commit is contained in:
parent
60af1efaad
commit
101cf9aeeb
21
api/main.go
21
api/main.go
|
@ -14,6 +14,7 @@ import (
|
||||||
type inbound struct {
|
type inbound struct {
|
||||||
Language string `json:"language"`
|
Language string `json:"language"`
|
||||||
Source string `json:"source"`
|
Source string `json:"source"`
|
||||||
|
Args []string `json:"args"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type problem struct {
|
type problem struct {
|
||||||
|
@ -75,19 +76,23 @@ func Execute(res http.ResponseWriter, req *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func launch(request inbound, res http.ResponseWriter) {
|
func launch(request inbound, res http.ResponseWriter) {
|
||||||
var ext string = "code";
|
stamp := time.Now().UnixNano()
|
||||||
|
|
||||||
if request.Language == "go" {
|
|
||||||
ext = "go"
|
|
||||||
}
|
|
||||||
|
|
||||||
// write the code to temp dir
|
// write the code to temp dir
|
||||||
filename := fmt.Sprintf("/tmp/%d." + ext, time.Now().UnixNano())
|
srcfile := fmt.Sprintf("/tmp/%d.code", stamp)
|
||||||
|
|
||||||
ioutil.WriteFile(filename, []byte(request.Source), 0644)
|
ioutil.WriteFile(srcfile, []byte(request.Source), 0644)
|
||||||
|
|
||||||
|
// set up the arguments to send to the execute command
|
||||||
|
var args []string
|
||||||
|
|
||||||
|
args = append(args, request.Language)
|
||||||
|
args = append(args, srcfile)
|
||||||
|
|
||||||
|
args = append(args, strings.Join(request.Args, "\n"))
|
||||||
|
|
||||||
// set up the execution
|
// set up the execution
|
||||||
cmd := exec.Command("../docker/execute", request.Language, filename)
|
cmd := exec.Command("../docker/execute", args...)
|
||||||
|
|
||||||
// capture out/err
|
// capture out/err
|
||||||
var stdout, stderr bytes.Buffer
|
var stdout, stderr bytes.Buffer
|
||||||
|
|
|
@ -14,6 +14,11 @@ fi
|
||||||
lang=$1
|
lang=$1
|
||||||
filepath=$(realpath $2)
|
filepath=$(realpath $2)
|
||||||
file=$(basename $2)
|
file=$(basename $2)
|
||||||
|
argpath="/tmp/$(date +%s%N).args"
|
||||||
|
arg=$(basename $argpath)
|
||||||
|
|
||||||
|
# write arg file
|
||||||
|
echo "${@:3}" > $argpath
|
||||||
|
|
||||||
bin=
|
bin=
|
||||||
case "$lang" in
|
case "$lang" in
|
||||||
|
@ -64,6 +69,7 @@ docker run \
|
||||||
--rm \
|
--rm \
|
||||||
--log-driver none \
|
--log-driver none \
|
||||||
-v $filepath:/$file:ro \
|
-v $filepath:/$file:ro \
|
||||||
|
-v $argpath:/$arg:ro \
|
||||||
-v $dir/executors/python2:/executor_python2:ro \
|
-v $dir/executors/python2:/executor_python2:ro \
|
||||||
-v $dir/executors/python3:/executor_python3:ro \
|
-v $dir/executors/python3:/executor_python3:ro \
|
||||||
-v $dir/executors/ruby:/executor_ruby:ro \
|
-v $dir/executors/ruby:/executor_ruby:ro \
|
||||||
|
@ -79,6 +85,7 @@ docker run \
|
||||||
piston \
|
piston \
|
||||||
runuser \
|
runuser \
|
||||||
-l runner \
|
-l runner \
|
||||||
-c "bash /$bin /$file $file ${@:3} 2>&1 | head -c 65536"
|
-c "bash /$bin /$file $file 2>&1 | head -c 65536"
|
||||||
|
|
||||||
rm -f /tmp/$file
|
rm -f /tmp/$file
|
||||||
|
rm -f /tmp/$arg
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
timeout -s KILL 10 gcc -o binary -x c $1
|
timeout -s KILL 10 gcc -o binary -x c $1
|
||||||
timeout -s KILL 3 ./binary ${@:3}
|
timeout -s KILL 3 cat /*.args | xargs -d '\n' ./binary
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
timeout -s KILL 10 g++ -o binary -x c++ $1
|
timeout -s KILL 10 g++ -o binary -x c++ $1
|
||||||
timeout -s KILL 3 ./binary ${@:3}
|
timeout -s KILL 3 cat /*.args | xargs -d '\n' ./binary
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
cp /*.code .
|
cp /*.code .
|
||||||
timeout -s KILL 10 mcs $(echo $1 | sed 's/\///') -out:binary
|
timeout -s KILL 10 mcs $(echo $1 | sed 's/\///') -out:binary
|
||||||
timeout -s KILL 3 mono binary ${@:3}
|
timeout -s KILL 3 cat /*.args | xargs -d '\n' mono binary
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
file=$1
|
cp /*.code interim.go
|
||||||
|
file="interim.go"
|
||||||
timeout -s KILL 10 go build $file
|
timeout -s KILL 10 go build $file
|
||||||
|
|
||||||
file=${file%%.*}
|
file=${file%%.*}
|
||||||
|
timeout -s KILL 3 cat /*.args | xargs -d '\n' ./$file
|
||||||
timeout -s KILL 3 ./$file ${@:3}
|
|
||||||
|
|
|
@ -2,4 +2,4 @@ cp /*.code interim.java
|
||||||
name=$(cat interim.java | grep -Eo 'public\s+class\s+([A-Za-z0-9]+)' | sed -n 's/ */ /gp' | cut -d' ' -f3)
|
name=$(cat interim.java | grep -Eo 'public\s+class\s+([A-Za-z0-9]+)' | sed -n 's/ */ /gp' | cut -d' ' -f3)
|
||||||
mv interim.java $name.java
|
mv interim.java $name.java
|
||||||
timeout -s KILL 10 javac $name.java
|
timeout -s KILL 10 javac $name.java
|
||||||
timeout -s KILL 3 java $name ${@:3}
|
timeout -s KILL 3 cat /*.args | xargs -d '\n' java $name
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
timeout -s KILL 10 nasm -f elf64 -o binary.o $1
|
timeout -s KILL 10 nasm -f elf64 -o binary.o $1
|
||||||
timeout -s KILL 10 ld binary.o -o binary
|
timeout -s KILL 10 ld binary.o -o binary
|
||||||
timeout -s KILL 3 ./binary ${@:3}
|
timeout -s KILL 3 cat /*.args | xargs -d '\n' ./binary
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
timeout -s KILL 3 nodejs $1 ${@:3}
|
timeout -s KILL 3 cat /*.args | xargs -d '\n' nodejs $1
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
timeout -s KILL 3 php $1 ${@:3}
|
timeout -s KILL 3 cat /*.args | xargs -d '\n' php $1
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
timeout -s KILL 3 python2 $1 ${@:3}
|
timeout -s KILL 3 cat /*.args | xargs -d '\n' python2 $1
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
timeout -s KILL 3 python3.6 $1 ${@:3}
|
timeout -s KILL 3 cat /*.args | xargs -d '\n' python3.6 $1
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
timeout -s KILL 3 Rscript $1 ${@:3}
|
timeout -s KILL 3 cat /*.args | xargs -d '\n' Rscript $1
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
timeout -s KILL 3 ruby $1 ${@:3}
|
timeout -s KILL 3 cat /*.args | xargs -d '\n' ruby $1
|
||||||
|
|
|
@ -10,7 +10,7 @@ from from EMKC contests and challenges. It's also used in the Engineer Man Disco
|
||||||
- `./build`
|
- `./build`
|
||||||
|
|
||||||
#### Usage
|
#### Usage
|
||||||
- `docker/execute <lang> <path to file>`
|
- `docker/execute [language] [path] [arg]...`
|
||||||
|
|
||||||
#### Supported Languages
|
#### Supported Languages
|
||||||
Currently python2, python3, c, c++, go, node, ruby, r, c#, nasm, php, and java is supported.
|
Currently python2, python3, c, c++, go, node, ruby, r, c#, nasm, php, and java is supported.
|
||||||
|
|
Loading…
Reference in New Issue