private List<String> collectProcessResults(Process process, ProcessBuilder builder,
      SubProcessIOFiles outPutFiles) throws Exception {

    List<String> results = new ArrayList<>();

    try {

      LOG.debug(String.format("Executing process %s", createLogEntryFromInputs(builder.command())));

      // If process exit value is not 0 then subprocess failed, record logs
      if (process.exitValue() != 0) {
        outPutFiles.copyOutPutFilesToBucket(configuration, FileUtils.toStringParams(builder));
        String log = createLogEntryForProcessFailure(process, builder.command(), outPutFiles);
        throw new Exception(log);
      }

      // If no return file then either something went wrong or the binary is setup incorrectly for
      // the ret file either way throw error
      if (!Files.exists(outPutFiles.resultFile)) {
        String log = createLogEntryForProcessFailure(process, builder.command(), outPutFiles);
        outPutFiles.copyOutPutFilesToBucket(configuration, FileUtils.toStringParams(builder));
        throw new Exception(log);
      }

      // Everything looks healthy return values
      try (Stream<String> lines = Files.lines(outPutFiles.resultFile)) {
        for (String line : (Iterable<String>) lines::iterator) {
          results.add(line);
        }
      }
      return results;
    } catch (Exception ex) {
      String log = String.format("Unexpected error runnng process. %s error message was %s",
          createLogEntryFromInputs(builder.command()), ex.getMessage());
      throw new Exception(log);
    }
  }
private List < String > collectProcessResults ( Process process , ProcessBuilder builder , SubProcessIOFiles outPutFiles ) throws Exception { List < String > results = new ArrayList < > ( ) ; try { LOG . debug ( String . format ( "Executing process %s" , createLogEntryFromInputs ( builder . command ( ) ) ) ) ; if ( process . exitValue ( ) != 0 ) { outPutFiles . copyOutPutFilesToBucket ( configuration , FileUtils . toStringParams ( builder ) ) ; String log = createLogEntryForProcessFailure ( process , builder . command ( ) , outPutFiles ) ; throw new Exception ( log ) ; } if ( ! Files . exists ( outPutFiles . resultFile ) ) { String log = createLogEntryForProcessFailure ( process , builder . command ( ) , outPutFiles ) ; outPutFiles . copyOutPutFilesToBucket ( configuration , FileUtils . toStringParams ( builder ) ) ; throw new Exception ( log ) ; } try ( Stream < String > lines = Files . lines ( outPutFiles . resultFile ) ) { for ( String line : ( Iterable < String > ) lines :: iterator ) { results . add ( line ) ; } } return results ; } catch ( Exception ex ) { String log = String . format ( "Unexpected error runnng process. %s error message was %s" , createLogEntryFromInputs ( builder . command ( ) ) , ex . getMessage ( ) ) ; throw new Exception ( log ) ; } }
TODO clean up duplicate with byte[] version collectBinaryProcessResults.
@param process
@param builder
@param outPutFiles
@return List of results
@throws Exception if process has non 0 value or no logs found then throw exception