Get system encoding?

Hi!

I have the following problem.

I use the ruby function Dir.getwd to get the working directory of my
running ruby application. I need to save this via a firebird adapter to
my DB.

When Dir.getwd contains special characters like “ß” the database insert
failes due to a wrong encoding. On my machine i have windows-1252
encoding, the firebird adapter requires utf-8. If i force a charset
conversion with iconv from windows-1252 to UTF-8 it works.

The open question is: How can i obtain the system encoding of my windows
machine?

hi christian!

Christian K. [2008-12-15 10:05]:

The open question is: How can i obtain the system encoding of my
windows machine?
would you mind giving ENV.user_encoding from ruby-nuggets a shot?
i’d be interested to see if that works for you.

gem:
http://rubyforge.org/projects/prometheus/

code:
http://github.com/blackwinter/ruby-nuggets/tree/master/lib/nuggets/env/user_encoding.rb

usage:
require ‘rubygems’
require ‘nuggets/env/user_encoding’

puts ENV.user_encoding

cheers
jens

Hi,

2008/12/15 Christian K. [email protected]:

encoding, the firebird adapter requires utf-8. If i force a charset
conversion with iconv from windows-1252 to UTF-8 it works.

The open question is: How can i obtain the system encoding of my windows
machine?
Try this

irb(main):001:0> “windows-#{chcp.scan(/\d+$/)}”
=> “windows-949”

HTH,

Park H.