Ruby on Windows - Ouput char Fixnum on console

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

Hi,

2013/6/25 jf Baillon [email protected]:

========================
print “test 200 \n”
put_cc 108.to_int

Hello Ruby

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

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 H.

Heesob P. wrote in post #1113488:

Hi,

2013/6/25 jf Baillon [email protected]:

========================
print “test 200 \n”
put_cc 108.to_int

Hello Ruby

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
Issues · cosmo0920/win32-api · GitHub

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 H.


Your help is providential.

Input one character with the keyboard and output on a console now works
well with FFI instead of win32/api.
I can do elementary word completion (like with an i-phone I have heard).
Using the keyboard and the mouse is the beginning of interactivity using
a computer and a language. Processing (the computer language) shows
using the mouse (or drawing a square) can be (very) easy. I shall try to
use Ruby and something like Processing simultaneously. Yet another
elementary thing to do : working with two programs. No help from MS
Windows system. But I have some ideas.

I hope I shall understand better how to use FFI than the last time I had
difficulties to resolve some problem. It seems to me there is much more
information on FFI today.

Users of Mac are smart, users of Linux are intelligent.
Add that some authors of programs or tools are esoteric (I should say
elegant, but it’s easy to understand when you know what it means).

I wish there is a place to help ordinary (I don’t like “dummy”) users
with MS Windows. (They could be numerous).

Thank you very much.