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.
Christian K. (Guest)
on 2008-12-15 11: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?
Jens W. (Guest)
on 2008-12-15 11:21
(Received via mailing list)
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/ma...

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

  puts ENV.user_encoding

cheers
jens
Heesob P. (Guest)
on 2008-12-15 11:27
(Received via mailing list)
Hi,

2008/12/15 Christian K. <removed_email_address@domain.invalid>:
> 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.
This topic is locked and can not be replied to.