Forum: Ruby Encoding for system calls on Windows

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
end

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
https://github.com/ruby/ruby/blob/d66c5768caaee16a...
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:
http://stackoverflow.com/a/17177904/156533

I'd like to know if

1) Is this a bug in ruby on Windows

or

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}`?
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.