From: Heesob Park Date: 2013-06-25T09:43:33+09:00 Subject: Re: Ruby on Windows - Ouput char Fixnum on console Hi, 2013/6/25 jf Baillon : > It's my first post here, and I have some > difficulties with english an with Ruby. > > Please can you give me some help. > > Ruby on Windows - Ouput char Fixnum on console. See attached file. > > After 'gem install win32-api --platform=ruby' in a command line > The following program [between the lines ========] > > ======================== > $stdout.sync=true > require 'win32/api' > include Win32 > > > def put_cc car # Ouput char Fixnum on console > a ||= API.new( '_putch', [], 'I', 'msvcrt') > a.call(car) > end > > print "test 200 \n" > > print 'ruby ', RUBY_VERSION, 'p', RUBY_PATCHLEVEL, " > (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] " > > b = [72, 101, 108, 108, 111, 32, 82, 117, 98, 121, 10] > print "\n" > b.each { |i| put_cc i } > > put_cc 72 > put_cc 101 > put_cc 108.to_int > put_cc 108 > put_cc 111 > put_cc 32 > put_cc 82 > put_cc 117 > put_cc 98 > put_cc 121 > put_cc 10 > > 'hola'.each_byte { |i| put_cc i } > > print "\n[Return] -> The end \n" > > gets > > ======================================= > gives with Ruby 193 [between the ------------] > ----------------------------- > test 200 > ruby 1.9.3p429 (2013-05-15) [i386-mingw32] > Hello Ruby > Hello Ruby > hola > [Return] -> The end > ----------------------------- > and with Ruby 2.0.0 > ----------------------------- > test 200 > ruby 2.0.0p195 (2013-05-14) [x64-mingw32] > ðððððððððððàààààààààààðððð > [Return] -> The end > ----------------------------- > > Attachments: > http://www.ruby-forum.com/attachment/8534/Ouput_char_Fixnum_on_console.rtf > The win32-api gem is not compatible with Ruby 2.0.0. If you want to use win32-api with Ruby 2.0.0, please make an issue on https://github.com/djberg96/win32-api/issues I recommend ffi instead of win32-api. You can do the same thing with ffi like this: ========================================== require 'ffi' module MyLib extend FFI::Library ffi_lib FFI::Platform::LIBC attach_function :_putch, [ :int ], :int end def put_cc car MyLib._putch(car) end 'hola'.each_byte { |i| put_cc i } ============================================ Regards, Park Heesob