From d4818213fc9ca5f4d5f5985f391f2fb126ff203c Mon Sep 17 00:00:00 2001 From: Ashar Fuadi Date: Sat, 26 Aug 2023 22:44:20 +0700 Subject: [PATCH] feat(grader): redirect solution's stderr to file during communication with communicator --- .../resources/engines/interactive/source/binsearch-OK.cpp | 3 +-- .../interactive/source/trigger-solution-sigpipe.cpp | 1 - .../gabriel/helpers/communicator/Communicator.java | 8 ++++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/judgels-backends/judgels-grader-engines/src/integTest/resources/engines/interactive/source/binsearch-OK.cpp b/judgels-backends/judgels-grader-engines/src/integTest/resources/engines/interactive/source/binsearch-OK.cpp index 1d07820de..a38875e5c 100644 --- a/judgels-backends/judgels-grader-engines/src/integTest/resources/engines/interactive/source/binsearch-OK.cpp +++ b/judgels-backends/judgels-grader-engines/src/integTest/resources/engines/interactive/source/binsearch-OK.cpp @@ -13,7 +13,6 @@ int main() fflush(stdout); fprintf(stderr, "debug"); - fflush(stderr); scanf("%s", response); @@ -22,4 +21,4 @@ int main() else hi = mid-1; } -} \ No newline at end of file +} diff --git a/judgels-backends/judgels-grader-engines/src/integTest/resources/engines/interactive/source/trigger-solution-sigpipe.cpp b/judgels-backends/judgels-grader-engines/src/integTest/resources/engines/interactive/source/trigger-solution-sigpipe.cpp index c0568564f..a93da4669 100644 --- a/judgels-backends/judgels-grader-engines/src/integTest/resources/engines/interactive/source/trigger-solution-sigpipe.cpp +++ b/judgels-backends/judgels-grader-engines/src/integTest/resources/engines/interactive/source/trigger-solution-sigpipe.cpp @@ -14,7 +14,6 @@ int main() fflush(stdout); fprintf(stderr, "debug"); - fflush(stderr); scanf("%s", response); diff --git a/judgels-backends/judgels-grader-engines/src/main/java/judgels/gabriel/helpers/communicator/Communicator.java b/judgels-backends/judgels-grader-engines/src/main/java/judgels/gabriel/helpers/communicator/Communicator.java index 3985e85a0..7df210627 100644 --- a/judgels-backends/judgels-grader-engines/src/main/java/judgels/gabriel/helpers/communicator/Communicator.java +++ b/judgels-backends/judgels-grader-engines/src/main/java/judgels/gabriel/helpers/communicator/Communicator.java @@ -29,6 +29,7 @@ public class Communicator { private static final String COMMUNICATION_OUTPUT_FILENAME = "_communication.out"; + private static final String SOLUTION_ERROR_FILENAME = "_solution.err"; private final SingleSourceFileCompiler compiler; private final TestCaseVerdictParser verdictParser; @@ -126,6 +127,13 @@ public EvaluationResult communicate(File input) throws EvaluationException { } } + solutionSandbox.resetRedirections(); + + // By default, stderr is not buffered. + // Writing to the unbuffered stderr sometimes interferes with the interaction. + // We redirect the stderr to a file so that it is buffered. + solutionSandbox.redirectStandardError(SOLUTION_ERROR_FILENAME); + try { FileUtils.cleanDirectory(communicationDir); } catch (IOException e) {