def withenv(hash, mode = :posix)
    saved = get_environment(mode)
    merge_environment(hash, mode)
    yield
  ensure
    if saved
      clear_environment(mode)
      merge_environment(saved, mode)
    end
  end
def withenv(hash, mode = :posix)
    saved = get_environment(mode)
    merge_environment(hash, mode)
    yield
  ensure
    if saved
      clear_environment(mode)
      merge_environment(saved, mode)
    end
  end
Run some code with a specific environment.  Resets the environment back to
 what it was at the end of the code.
 Windows can store Unicode chars in the environment as keys or values, but
 Ruby's ENV tries to roundtrip them through the local codepage, which can
 cause encoding problems - underlying helpers use Windows APIs on Windows
 see https://bugs.ruby-lang.org/issues/8822