{"id":"ceb043e7a8d3bcf0","repo":"junit-team/junit5","slug":"error-redirecting-stdout-and-stderr-to-file-std","errorCode":null,"errorMessage":"Error redirecting stdout and stderr to file: ${stdoutPath}","messagePattern":"Error redirecting stdout and stderr to file: (.+?)","errorType":"exception","errorClass":"JUnitException","httpStatus":null,"severity":"error","filePath":"junit-platform-console/src/main/java/org/junit/platform/console/command/StandardStreamsHandler.java","lineNumber":51,"sourceCode":"\t *\n\t * <p>If the paths are the same, both streams are redirected to the same file.\n\t *\n\t * <p>The default charset is used for writing to the files.\n\t *\n\t * @param stdoutPath the file path for standard output, or {@code null} to\n\t * indicate no redirection\n\t * @param stderrPath the file path for standard error, or {@code null} to\n\t * indicate no redirection\n\t */\n\tpublic void redirectStandardStreams(@Nullable Path stdoutPath, @Nullable Path stderrPath) {\n\t\tif (isSameFile(stdoutPath, stderrPath)) {\n\t\t\ttry {\n\t\t\t\tPrintStream commonStream = new PrintStream(Files.newOutputStream(stdoutPath), true);\n\t\t\t\tthis.stdout = commonStream;\n\t\t\t\tthis.stderr = commonStream;\n\t\t\t}\n\t\t\tcatch (IOException ex) {\n\t\t\t\tthrow new JUnitException(\"Error redirecting stdout and stderr to file: \" + stdoutPath, ex);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tif (stdoutPath != null) {\n\t\t\t\ttry {\n\t\t\t\t\tthis.stdout = new PrintStream(Files.newOutputStream(stdoutPath), true);\n\t\t\t\t}\n\t\t\t\tcatch (IOException ex) {\n\t\t\t\t\tthrow new JUnitException(\"Error redirecting stdout to file: \" + stdoutPath, ex);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (stderrPath != null) {\n\t\t\t\ttry {\n\t\t\t\t\tthis.stderr = new PrintStream(Files.newOutputStream(stderrPath), true);\n\t\t\t\t}\n\t\t\t\tcatch (IOException ex) {\n\t\t\t\t\tthrow new JUnitException(\"Error redirecting stderr to file: \" + stderrPath, ex);","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/junit-team/junit5/blob/956246301e03d757539f7b76dd5a91f298637563/junit-platform-console/src/main/java/org/junit/platform/console/command/StandardStreamsHandler.java#L33-L69","documentation":"Error \"Error redirecting stdout and stderr to file: ${stdoutPath}\" thrown in junit-team/junit5.","triggerScenarios":"Thrown at junit-platform-console/src/main/java/org/junit/platform/console/command/StandardStreamsHandler.java:51 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}