<commit_before>package scalan.util

import java.io.{InputStreamReader, BufferedReader, File}

object ProcessUtil {
  def launch(workingDir: File, command: String*) {
    val builder = new ProcessBuilder(command: _*)
    val absoluteWorkingDir = workingDir.getAbsoluteFile
    builder.directory(absoluteWorkingDir)
    builder.inheritIO()
    val proc = builder.start()
    val exitCode = proc.waitFor()
    if (exitCode != 0) {
      val stream = proc.getInputStream
      try {
        val sb = new StringBuilder()
        val reader = new BufferedReader(new InputStreamReader(stream))
        var line: String = reader.readLine()
        while (line != null) {
          sb.append(line).append("\n")
          line = reader.readLine()
        }
        throw new RuntimeException(s"Executing '${command.mkString(" ")}' in directory $absoluteWorkingDir returned exit code $exitCode with following output:\n$sb")
      } finally {
        stream.close()
      }
    } else {
      // program executed successfully
    }
  }

}<commit_msg>Fix process output not showing up in the exception<commit_after>package scalan.util

import java.io.{InputStreamReader, BufferedReader, File}

object ProcessUtil {
  def launch(workingDir: File, command: String*) {
    val absoluteWorkingDir = workingDir.getAbsoluteFile
    val builder = new ProcessBuilder(command: _*).
      directory(absoluteWorkingDir).
      redirectErrorStream(true)
    val proc = builder.start()
    val exitCode = proc.waitFor()
    val output = readOutput(proc)
    if (exitCode != 0) {
      throw new RuntimeException(s"Executing '${command.mkString(" ")}' in directory $absoluteWorkingDir returned exit code $exitCode with following output:\n$output")
    } else {
      Console.print(output)
    }
  }

  def readOutput(process: Process) = {
    val stream = process.getInputStream
    try {
      val sb = new StringBuilder()
      val reader = new BufferedReader(new InputStreamReader(stream))
      var line: String = reader.readLine()
      while (line != null) {
        sb.append(line).append("\n")
        line = reader.readLine()
      }
      sb.result()
    } finally {
      stream.close()
    }
  }
}
{'fraction_non_alphanumeric': 0.1076993583868011, 'fraction_numerical': 0.0009165902841429881, 'mean_word_length': 2.9908592321755028, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '366519', 'n_tokens_mistral': 613, 'n_tokens_neox': 602, 'n_words': 161}