问题
I am using ProcessBuilder
to run an executable file from another directory. I'm also redirecting output and error to files in the local directory. But strangely my error file shows the output of the executable and the output file is blank. I am not sure what is going on, can someone please shed some light on my situation.
My code:
File outputFile = new File("outputLog.txt");
File errorFile = new File("ErrLog.txt");
List<String> command = Arrays.asList("c:\\dataloader\\TestDataLoader.exe", "-h");
ProcessBuilder probuilder = new ProcessBuilder(command);
//redirect output
probuilder.redirectOutput(outputFile);
probuilder.redirectError(errorFile);
Process process = probuilder.start();
process.waitFor();
printFile(errorFile); //writes to file
printFile(outputFile); //writes to file
int exitValue = process.exitValue();
System.out.println("\n\nExit Value is " + exitValue);
来源:https://stackoverflow.com/questions/44852336/process-builder-output-and-error-redirection