<commit_before>module Heathen

  # An Executioner object will execute the given command, storing exit status,
  # STDOUT and STDERR for perusal.
  class Executioner
    attr_reader :logger, :last_exit_status, :last_messages, :last_command,
      :stdout, :stderr

    def initialize(log)
      @logger = log
    end

    # Executes the given command.
    #   argv[0] is the command to run
    #   argv[1+] are the command arguments
    #   argv[n] can be a [Hash] of options for the execution:
    #      :binary - STDOUT, STDERR are expected to be binary, so shouldn't be logged
    #      :dir    - execution directory
    def execute(*argv)
      options = argv.last.class == Hash ? argv.pop : {}

      started = Time.now.to_f

      command = argv.map(&:to_s)

      pid, status, @stdout, @stderr = _execute(*command, options)

      elapsed = Time.now.to_f - started

      if status != 0
        logger.error "[#{pid}] exited with status #{status.inspect}"
      end
      logger.info("[#{pid}] completed in %02.4f" % elapsed)

      @stdout.strip!
      @stderr.strip!

      logger.info "  stdout: '#@stdout'" unless @stdout.empty? unless options[:binary]
      logger.info "  stderr: '#@stderr'" unless @stderr.empty?

      @last_exit_status = status
      @last_messages = {stdout: @stdout, stderr: @stderr}
      @last_command = command.join(' ')

      return status
    end

    if RUBY_PLATFORM == 'java'
      # Executes the given argument vector with ProcessBuilder.<commit_msg>execute: log PID alongside stdout/stderr<commit_after>module Heathen

  # An Executioner object will execute the given command, storing exit status,
  # STDOUT and STDERR for perusal.
  class Executioner
    attr_reader :logger, :last_exit_status, :last_messages, :last_command,
      :stdout, :stderr

    def initialize(log)
      @logger = log
    end

    # Executes the given command.
    #   argv[0] is the command to run
    #   argv[1+] are the command arguments
    #   argv[n] can be a [Hash] of options for the execution:
    #      :binary - STDOUT, STDERR are expected to be binary, so shouldn't be logged
    #      :dir    - execution directory
    def execute(*argv)
      options = argv.last.class == Hash ? argv.pop : {}

      started = Time.now.to_f

      command = argv.map(&:to_s)

      pid, status, @stdout, @stderr = _execute(*command, options)

      elapsed = Time.now.to_f - started

      if status != 0
        logger.error "[#{pid}] exited with status #{status.inspect}"
      end
      logger.info("[#{pid}] completed in %02.4f" % elapsed)

      @stdout.strip!
      @stderr.strip!

      logger.info "[#{pid}] stdout: '#@stdout'" unless @stdout.empty? unless options[:binary]
      logger.info "[#{pid}] stderr: '#@stderr'" unless @stderr.empty?

      @last_exit_status = status
      @last_messages = {stdout: @stdout, stderr: @stderr}
      @last_command = command.join(' ')

      return status
    end

    if RUBY_PLATFORM == 'java'
      # Executes the given argument vector with ProcessBuilder.
{'fraction_non_alphanumeric': 0.11275964391691394, 'fraction_numerical': 0.003956478733926805, 'mean_word_length': 2.709046454767726, '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': '5143296', 'n_tokens_mistral': 949, 'n_tokens_neox': 914, 'n_words': 289}