Forum: Ruby get system encoding?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A40ea9c816d41de88a806fecfaf1afb6?d=identicon&s=25 Christian Kerth (kerthi)
on 2008-12-15 10:12
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?
Fe5660da5930df2d7b34b6066c2d16bb?d=identicon&s=25 Jens Wille (jwille)
on 2008-12-15 10:21
(Received via mailing list)
hi christian!

Christian Kerth [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/ma...

usage:
  require 'rubygems'
  require 'nuggets/env/user_encoding'

  puts ENV.user_encoding

cheers
jens
666b4e17b4bb0e2d999037a25f65a7cb?d=identicon&s=25 Heesob Park (phasis)
on 2008-12-15 10:27
(Received via mailing list)
Hi,

2008/12/15 Christian Kerth <christian.kerth@dynamicmedia.at>:
> 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 Heesob
This topic is locked and can not be replied to.