I have a problem with Ruby (1.9.3) and Powershell.
I need to write an interactive console application that will deal with offers in Polish. They helped me and can extract ARGV elements with Polish diacritics, but the standard input does not work the way I want.
Code designation:
target = ARGV[0].dup.force_encoding('CP1250').encode('UTF-8')
puts "string constant = dupą"
puts "dupą".bytes.to_a.to_s
puts "dupą".encoding
puts "target = " +target
puts target.bytes.to_a.to_s
puts target.encoding
puts target.eql? "dupą"
STDIN.set_encoding("CP1250", "UTF-8")
target2 = STDIN.gets
puts "target2 = " +target2
puts target2.bytes.to_a.to_s
puts target2.encoding
puts target2.eql? "dupą"
Output:
string constant = dupą
[100, 117, 112, 196, 133]
UTF-8
target = dupą
[100, 117, 112, 196, 133]
UTF-8
true
dupą
target2 = dup
[100, 117, 112]
UTF-8
false
Apparently, Ruby never gets the fourth character from STDIN.gets. If I write a longer line, for example dupąlalala, only three initial bytes still appear inside the program.
- I tried to list the bytes and the loop using getc, but they never reach Ruby (where are they lost?)
- I used chcp 65001 (it seems nothing changes)
I changed my $ OutputEncoding to [Console] :: OutputEncoding; now it looks like this:
IsSingleByte : True
BodyName : ibm852
EncodingName : Środkowoeuropejski (DOS)
HeaderName : ibm852
WebName : ibm852
WindowsCodePage : 1250
IsBrowserDisplay : True
IsBrowserSave : True
IsMailNewsDisplay : False
IsMailNewsSave : False
EncoderFallback : System.Text.InternalEncoderBestFitFallback
DecoderFallback : System.Text.InternalDecoderBestFitFallback
IsReadOnly : True
CodePage : 852
Consolas
, - Powershell?