<commit_before>module Gitlab
  module Popen
    def popen(cmd, path)
      vars = { "PWD" => path }
      options = { chdir: path }

      @cmd_output = ""
      @cmd_status = 0
      Open3.popen3(vars, cmd, options) do |stdin, stdout, stderr, wait_thr|
        @cmd_status = wait_thr.value.exitstatus
        @cmd_output << stdout.read
        @cmd_output << stderr.read
      end

      return @cmd_output, @cmd_status
    end
  end
end<commit_msg>Ensure directory exists before changing in popen<commit_after>
require 'fileutils'

module Gitlab
  module Popen
    def popen(cmd, path)
      vars = { "PWD" => path }
      options = { chdir: path }

      unless File.directory?(path)
       FileUtils.mkdir_p(path)
      end

      @cmd_output = ""
      @cmd_status = 0
      Open3.popen3(vars, cmd, options) do |stdin, stdout, stderr, wait_thr|
        @cmd_status = wait_thr.value.exitstatus
        @cmd_output << stdout.read
        @cmd_output << stderr.read
      end

      return @cmd_output, @cmd_status
    end
  end
end
{'fraction_non_alphanumeric': 0.10154738878143134, 'fraction_numerical': 0.005802707930367505, 'mean_word_length': 2.3934426229508197, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, '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': '6094979', 'n_tokens_mistral': 360, 'n_tokens_neox': 353, 'n_words': 86}