diff --git a/docker/bash/run.sh b/docker/bash/run.sh index 05fbe98..1800c0b 100644 --- a/docker/bash/run.sh +++ b/docker/bash/run.sh @@ -1,2 +1,6 @@ +mkdir "$COUNT" && cd "$COUNT" + echo "$1" > program.sh bash program.sh + +cd .. && rm -rf "$COUNT" diff --git a/docker/c/run.sh b/docker/c/run.sh index 3759528..320a72e 100644 --- a/docker/c/run.sh +++ b/docker/c/run.sh @@ -1,2 +1,6 @@ +mkdir "$COUNT" && cd "$COUNT" + echo "$1" > program.c gcc program.c -o program && ./program + +cd .. && rm -rf "$COUNT" diff --git a/docker/clojure/run.sh b/docker/clojure/run.sh index 1804e0a..50d637e 100644 --- a/docker/clojure/run.sh +++ b/docker/clojure/run.sh @@ -1,2 +1,6 @@ +mkdir "$COUNT" && cd "$COUNT" + echo "$1" > program.clj clojure program.clj + +cd .. && rm -rf "$COUNT" diff --git a/docker/cpp/run.sh b/docker/cpp/run.sh index cd796f4..afc410f 100644 --- a/docker/cpp/run.sh +++ b/docker/cpp/run.sh @@ -1,2 +1,6 @@ +mkdir "$COUNT" && cd "$COUNT" + echo "$1" > program.cpp g++ program.cpp -o program && ./program + +cd .. && rm -rf "$COUNT" diff --git a/docker/csharp/run.sh b/docker/csharp/run.sh index f848c24..8afc09a 100644 --- a/docker/csharp/run.sh +++ b/docker/csharp/run.sh @@ -1,6 +1,10 @@ if [ "$EVAL_EXPR" = "true" ]; then csharp -e "$1" else + mkdir "$COUNT" && cd "$COUNT" + echo "$1" > program.cs csc program.cs >/dev/null && mono program.exe + + cd .. && rm -rf "$COUNT" fi diff --git a/docker/elixir/run.sh b/docker/elixir/run.sh index 6520a90..d7e3dff 100644 --- a/docker/elixir/run.sh +++ b/docker/elixir/run.sh @@ -1,2 +1,6 @@ +mkdir "$COUNT" && cd "$COUNT" + echo "$1" > program.exs elixir program.exs + +cd .. && rm -rf "$COUNT" diff --git a/docker/fsharp/run.sh b/docker/fsharp/run.sh index c588ac2..105eab7 100644 --- a/docker/fsharp/run.sh +++ b/docker/fsharp/run.sh @@ -1,2 +1,6 @@ +mkdir "$COUNT" && cd "$COUNT" + echo "$1" > program.fs fsharpc --optimize- program.fs >/dev/null && mono program.exe + +cd .. && rm -rf "$COUNT" diff --git a/docker/go/run.sh b/docker/go/run.sh index 0e12614..552f823 100644 --- a/docker/go/run.sh +++ b/docker/go/run.sh @@ -1,2 +1,6 @@ +mkdir "$COUNT" && cd "$COUNT" + echo "$1" > program.go go run program.go + +cd .. && rm -rf "$COUNT" diff --git a/docker/haskell/run.sh b/docker/haskell/run.sh index 911cf4e..b33926a 100644 --- a/docker/haskell/run.sh +++ b/docker/haskell/run.sh @@ -1,6 +1,13 @@ if [ "$EVAL_EXPR" = "true" ]; then ghc -e "$1" else + mkdir "$COUNT" && cd "$COUNT" + echo "$1" > program.hs - ghc -O0 -j +RTS -A128m -n2m -RTS program.hs >/dev/null && ./program + ghc -O0 -j +RTS -A128m -n2m -RTS \ + -no-keep-o-files -no-keep-hi-files \ + program.hs >/dev/null \ + && ./program + + cd .. && rm -rf "$COUNT" fi diff --git a/docker/java/run.sh b/docker/java/run.sh index 46b2f03..15f4f16 100644 --- a/docker/java/run.sh +++ b/docker/java/run.sh @@ -1,2 +1,6 @@ +mkdir "$COUNT" && cd "$COUNT" + echo "$1" > Main.java javac Main.java && java Main + +cd .. && rm -rf "$COUNT" diff --git a/docker/lua/run.sh b/docker/lua/run.sh index 39c3e24..b3e9ea0 100644 --- a/docker/lua/run.sh +++ b/docker/lua/run.sh @@ -1,2 +1,6 @@ +mkdir "$COUNT" && cd "$COUNT" + echo "$1" > program.lua lua5.3 program.lua + +cd .. && rm -rf "$COUNT" diff --git a/docker/ocaml/run.sh b/docker/ocaml/run.sh index 6e61446..4e81749 100644 --- a/docker/ocaml/run.sh +++ b/docker/ocaml/run.sh @@ -1,2 +1,6 @@ +mkdir "$COUNT" && cd "$COUNT" + echo "$1" > program.ml ocamlopt -cclib --static -o program program.ml && ./program + +cd .. && rm -rf "$COUNT" diff --git a/docker/pascal/run.sh b/docker/pascal/run.sh index 4903b85..06f7765 100644 --- a/docker/pascal/run.sh +++ b/docker/pascal/run.sh @@ -1,3 +1,5 @@ +mkdir "$COUNT" && cd "$COUNT" + echo "$1" > program.pas # fpc does not use stderr, ld however does, capture both @@ -9,3 +11,5 @@ else echo "$res" exit 1 fi + +cd .. && rm -rf "$COUNT" diff --git a/docker/perl/run.sh b/docker/perl/run.sh index 6e9c849..a071311 100644 --- a/docker/perl/run.sh +++ b/docker/perl/run.sh @@ -1,2 +1,6 @@ +mkdir "$COUNT" && cd "$COUNT" + echo "$1" > program.pl perl program.pl + +cd .. && rm -rf "$COUNT" diff --git a/docker/prolog/run.sh b/docker/prolog/run.sh index 6217036..e3786cb 100644 --- a/docker/prolog/run.sh +++ b/docker/prolog/run.sh @@ -1,2 +1,6 @@ +mkdir "$COUNT" && cd "$COUNT" + echo "$1" > program.pl swipl --quiet program.pl + +cd .. && rm -rf "$COUNT" diff --git a/docker/python2/run.sh b/docker/python2/run.sh index f07bd5a..c67d836 100644 --- a/docker/python2/run.sh +++ b/docker/python2/run.sh @@ -1,2 +1,6 @@ +mkdir "$COUNT" && cd "$COUNT" + echo "$1" > program.py python program.py + +cd .. && rm -rf "$COUNT" diff --git a/docker/python3/run.sh b/docker/python3/run.sh index f07bd5a..c67d836 100644 --- a/docker/python3/run.sh +++ b/docker/python3/run.sh @@ -1,2 +1,6 @@ +mkdir "$COUNT" && cd "$COUNT" + echo "$1" > program.py python program.py + +cd .. && rm -rf "$COUNT" diff --git a/docker/racket/run.sh b/docker/racket/run.sh index cb37584..91f9992 100644 --- a/docker/racket/run.sh +++ b/docker/racket/run.sh @@ -1,2 +1,6 @@ +mkdir "$COUNT" && cd "$COUNT" + echo "$1" > program.rkt racket program.rkt + +cd .. && rm -rf "$COUNT" diff --git a/docker/ruby/run.sh b/docker/ruby/run.sh index 457bd54..ebf6738 100644 --- a/docker/ruby/run.sh +++ b/docker/ruby/run.sh @@ -1,2 +1,6 @@ +mkdir "$COUNT" && cd "$COUNT" + echo "$1" > program.rb ruby program.rb + +cd .. && rm -rf "$COUNT" diff --git a/docker/rust/run.sh b/docker/rust/run.sh index ff63881..f659f53 100644 --- a/docker/rust/run.sh +++ b/docker/rust/run.sh @@ -1,2 +1,6 @@ +mkdir "$COUNT" && cd "$COUNT" + echo "$1" > program.rs rustc -C opt-level=0 --color never program.rs && ./program + +cd .. && rm -rf "$COUNT" diff --git a/src/struct/LanguageHandler.js b/src/struct/LanguageHandler.js index a71058d..32fe4b4 100644 --- a/src/struct/LanguageHandler.js +++ b/src/struct/LanguageHandler.js @@ -74,7 +74,7 @@ class LanguageHandler extends AkairoHandler { try { await this.handleSpawn(proc); - this.containers.set(id, { name }); + this.containers.set(id, { name, count: 0 }); return this.containers.get(id); } catch (err) { throw err; @@ -83,9 +83,10 @@ class LanguageHandler extends AkairoHandler { async evalCode({ language, code, options }) { const { id = language.id, env = {} } = language.runWith(options); - const { name } = await this.setupContainer(id); + const { name, count } = await this.setupContainer(id); const proc = childProcess.spawn('docker', [ 'exec', + `-eCOUNT=${count}`, ...Object.entries(env).map(([k, v]) => `-e${k}=${v}`), name, '/bin/sh', '/var/run/run.sh', code ]);