module Cucumber::WindowsOutput

def self.extended(o)

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

def cucumber_preprocess_output(*a)

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

def print(*a)

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

def puts(*a)

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