module Cucumber::WindowsOutput

def self.extended(output)

def self.extended(output)
  output.instance_eval do
    def cucumber_preprocess_output(*out)
      out.map { |arg| arg.to_s.encode(Encoding.default_external) }
    rescue Encoding::UndefinedConversionError => e
      STDERR.cucumber_puts("WARNING: #{e.message}")
      out
    end
    alias cucumber_print print
    def print(*out)
      cucumber_print(*cucumber_preprocess_output(*out))
    end
    alias cucumber_puts puts
    def puts(*out)
      cucumber_puts(*cucumber_preprocess_output(*out))
    end
  end
end

def cucumber_preprocess_output(*out)

def cucumber_preprocess_output(*out)
  out.map { |arg| arg.to_s.encode(Encoding.default_external) }
rescue Encoding::UndefinedConversionError => e
  STDERR.cucumber_puts("WARNING: #{e.message}")
  out
end

def print(*out)

def print(*out)
  cucumber_print(*cucumber_preprocess_output(*out))
end

def puts(*out)

def puts(*out)
  cucumber_puts(*cucumber_preprocess_output(*out))
end