Forum: Ruby Encoding for system calls on Windows

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
10adb7caa4eff9c02d244172bc8db6df?d=identicon&s=25 Joshua F. (joshua_f)
on 2013-10-22 03:31
Attachment: spawn_encode.rb (313 Bytes)
I am trying to understand how encoding interacts with system calls,
particularly on Windows.
I suspect there may be a bug in ruby on how it invokes system calls with
non-ASCII characters in the command.

I have a demonstration program below (also attached, in case the
encoding gets corrupted in the mailing list). It fails on Windows 7 and
Windows XP, even when I "chcp 65001". I have my Command Prompt
configured to use Lucinda Console font (as default Raster fonts have
even more problems with non-ASCII characters).

# encoding: utf-8

def test(word)
  returned = `echo #{word}`.chomp
  puts "#{word} == #{returned}"
  raise "Cannot roundtrip #{word}" unless word == returned

test "good"

test "bÃd"

puts "Success"

# win7, cmd.exe font set to Lucinda Console, chcp 65001
# good == good
# bÃd == bÃd

I suspect that something in here
needs to make sure the string being passed to the cmd.exe process is
encoded properly, but I'm in over my head.
I also suspect that this response hold a clue about the change that may
need to be made:

I'd like to know if

1) Is this a bug in ruby on Windows


2) How can I change the program above so that it completes successfully
on Windows?
3be79c5e7acf4f3a86d7870f0c3991b5?d=identicon&s=25 Alex aka Sinm (Guest)
on 2013-10-23 16:47
(Received via mailing list)
Have you tried something like `chcp 65001; echo #{word}`?
This topic is locked and can not be replied to.