# Get system encoding?

**URL:** <https://www.ruby-forum.com/t/get-system-encoding/155650>\
**Category:** Ruby\
**Created:** [December 15, 2008, 10:12am UTC](https://www.ruby-forum.com/t/get-system-encoding/155650 "2008-12-15T10:12:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sealedsun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@sealedsun](https://www.ruby-forum.com/u/sealedsun)\
**Post date:** [December 15, 2008, 10:12am UTC](https://www.ruby-forum.com/t/get-system-encoding/155650/1 "2008-12-15T10:12:27Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![sealedsun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@sealedsun](https://www.ruby-forum.com/u/sealedsun)\
**Post date:** [December 15, 2008, 10:21am UTC](https://www.ruby-forum.com/t/get-system-encoding/155650/2 "2008-12-15T10:21:45Z")

</div>

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/](http://rubyforge.org/projects/prometheus/)

code:  
[http://github.com/blackwinter/ruby-nuggets/tree/master/lib/nuggets/env/user\_encoding.rb](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

---

<div class="post-metadata">

**Author:** ![sealedsun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@sealedsun](https://www.ruby-forum.com/u/sealedsun)\
**Post date:** [December 15, 2008, 10:27am UTC](https://www.ruby-forum.com/t/get-system-encoding/155650/3 "2008-12-15T10:27:37Z")

</div>

Hi,

2008/12/15 Christian K. [removed\_email\_address@domain.invalid](mailto: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.
