module Gem::Util

def self.silent_system *command

def self.silent_system *command
  opt = {:out => NULL_DEVICE, :err => [:child, :out]}
  if Hash === command.last
    opt.update(command.last)
    cmds = command[0...-1]
  else
    cmds = command.dup
  end
  return system(*(cmds << opt))
rescue TypeError
  require 'thread'
  @silent_mutex ||= Mutex.new
  null_device = NULL_DEVICE
  @silent_mutex.synchronize do
    begin
      stdout = STDOUT.dup
      stderr = STDERR.dup
      STDOUT.reopen null_device, 'w'
      STDERR.reopen null_device, 'w'
      return system(*command)
    ensure
      STDOUT.reopen stdout
      STDERR.reopen stderr
      stdout.close
      stderr.close
    end
  end
end