Process builder output and error redirection

会有一股神秘感。 提交于 2019-12-10 10:55:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!