Skip to content

Commit

Permalink
feat(grader): redirect solution's stderr to file during communication…
Browse files Browse the repository at this point in the history
… with communicator (#502)
  • Loading branch information
fushar authored Aug 26, 2023
1 parent 55c025d commit d62304f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ int main()
fflush(stdout);

fprintf(stderr, "debug");
fflush(stderr);

scanf("%s", response);

Expand All @@ -22,4 +21,4 @@ int main()
else
hi = mid-1;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ int main()
fflush(stdout);

fprintf(stderr, "debug");
fflush(stderr);

scanf("%s", response);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit d62304f

Please sign in to comment.