<commit_before>require 'ffi'
require 'thread'

module ChildProcess
  module Unix
    class PosixSpawnProcess < Process
      private

      @@cwd_lock = Mutex.new

      def launch_process
        pid_ptr = FFI::MemoryPointer.new(:pid_t)
        actions = Lib::FileActions.new
        attrs   = Lib::Attrs.new

        if io.stdout
          actions.add_dup fileno_for(io.stdout), fileno_for($stdout)
        else
          actions.add_open fileno_for($stdout), "/dev/null", File::WRONLY, 0644
        end

        if io.stderr
          actions.add_dup fileno_for(io.stderr), fileno_for($stderr)
        else
          actions.add_open fileno_for($stderr), "/dev/null", File::WRONLY, 0644
        end

        if duplex?
          reader, writer = ::IO.pipe
          actions.add_dup fileno_for(reader), fileno_for($stdin)
          actions.add_close fileno_for(writer)
        end
<commit_msg>Fix posix_spawn bug when $stdout is overriden<commit_after>require 'ffi'
require 'thread'

module ChildProcess
  module Unix
    class PosixSpawnProcess < Process
      private

      @@cwd_lock = Mutex.new

      def launch_process
        pid_ptr = FFI::MemoryPointer.new(:pid_t)
        actions = Lib::FileActions.new
        attrs   = Lib::Attrs.new

        if io.stdout
          actions.add_dup fileno_for(io.stdout), fileno_for(STDOUT)
        else
          actions.add_open fileno_for(STDOUT), "/dev/null", File::WRONLY, 0644
        end

        if io.stderr
          actions.add_dup fileno_for(io.stderr), fileno_for(STDERR)
        else
          actions.add_open fileno_for(STDERR), "/dev/null", File::WRONLY, 0644
        end

        if duplex?
          reader, writer = ::IO.pipe
          actions.add_dup fileno_for(reader), fileno_for(STDIN)
          actions.add_close fileno_for(writer)
        end

{'fraction_non_alphanumeric': 0.09356081452944413, 'fraction_numerical': 0.008805723720418272, 'mean_word_length': 2.2994555353901998, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2225302', 'n_tokens_mistral': 599, 'n_tokens_neox': 567, 'n_words': 120}