Skip to content

Commit

Permalink
#308 Read the error stream from executable in BBUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
erikpelgrim committed Jun 8, 2023
1 parent 7cf5693 commit a004c5f
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions core/java/src/org/openda/blackbox/config/BBUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,9 @@ public static int runExecutable(String exePath, File fileOrDir, String[] argumen
System.out.println("workingDir="+workingDir);
process = Runtime.getRuntime().exec(commandArgs, null, workingDir);

BufferedReader stdInput = new BufferedReader(new
InputStreamReader(process.getInputStream()));
writeProcessOutputToSystemOut(process);

//Tunnel screen output of executable's stdout
String line;
System.out.println("<OUTPUT>");
while ((line = stdInput.readLine()) != null)
System.out.println(line);
System.out.println("</OUTPUT>");
writeProcessErrorToSystemOut(process);

//wait until executable is finished
exitValue = process.waitFor();
Expand All @@ -225,7 +219,28 @@ public static int runExecutable(String exePath, File fileOrDir, String[] argumen
return exitValue;
}

public static Object runJavaClass(String className, File fileOrDir, String[] arguments) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
private static void writeProcessOutputToSystemOut(Process process) throws IOException {
BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));

//Tunnel screen output of executable's stdout
String line;
System.out.println("<OUTPUT>");
while ((line = stdInput.readLine()) != null) {
System.out.println(line);
}
System.out.println("</OUTPUT>");
}

private static void writeProcessErrorToSystemOut(Process process) throws IOException {
BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String errorLine;
System.out.println("<ERROR>");
while ((errorLine = stdError.readLine()) != null)
System.out.println(errorLine);
System.out.println("</ERROR>");
}

public static Object runJavaClass(String className, File fileOrDir, String[] arguments) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
Object retClass = null;
// Create instance of class and run it
final Class javaClass;
Expand Down

0 comments on commit a004c5f

Please sign in to comment.