# Ruby on Windows - Ouput char Fixnum on console

**URL:** <https://rubytalk.org/t/ruby-on-windows-ouput-char-fixnum-on-console/68079>\
**Category:** ruby-talk\
**Created:** [24 June 2013 18:17 UTC](https://rubytalk.org/t/ruby-on-windows-ouput-char-fixnum-on-console/68079 "2013-06-24T18:17:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [24 June 2013 18:17 UTC](https://rubytalk.org/t/ruby-on-windows-ouput-char-fixnum-on-console/68079/1 "2013-06-24T18:17:47Z")

</div>

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  
> &nbsp;&nbsp;&nbsp;&nbsp;a ||= API.new( '\_putch', [], 'I', 'msvcrt')  
> &nbsp;&nbsp;&nbsp;&nbsp;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](http://www.ruby-forum.com/attachment/8534/Ouput_char_Fixnum_on_console.rtf)
> 
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Heesob\_Park](https://avatars.discourse-cdn.com/v4/letter/h/3bc359/32.png) [@Heesob\_Park](https://rubytalk.org/u/Heesob_Park)\
**Post date:** [25 June 2013 00:43 UTC](https://rubytalk.org/t/ruby-on-windows-ouput-char-fixnum-on-console/68079/2 "2013-06-25T00:43:33Z")

</div>

Hi,

> **···**
>
> 2013/6/25 jf Baillon \<lists@ruby-forum.com\>:
> 
> > 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  
> > &nbsp;&nbsp;&nbsp;&nbsp;a ||= API.new( '\_putch', , 'I', 'msvcrt')  
> > &nbsp;&nbsp;&nbsp;&nbsp;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](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
> 
> > **[cosmo0920/win32-api](https://github.com/cosmo0920/win32-api/issues)**
> >
> > A different, better variant of the Win32API Ruby library - cosmo0920/win32-api
> 
> # I recommend ffi instead of win32-api. You can do the same thing with ffi like this:
> 
> require 'ffi'
> 
> module MyLib  
> &nbsp;&nbsp;extend FFI::Library  
> &nbsp;&nbsp;ffi\_lib FFI::Platform::LIBC  
> &nbsp;&nbsp;attach\_function :\_putch, [:int], :int  
> end
> 
> def put\_cc car  
> &nbsp;&nbsp;&nbsp;&nbsp;MyLib.\_putch(car)  
> end
> 
> # 'hola'.each\_byte { |i| put\_cc i }
> 
> Regards,  
> Park Heesob

---

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [25 June 2013 17:12 UTC](https://rubytalk.org/t/ruby-on-windows-ouput-char-fixnum-on-console/68079/3 "2013-06-25T17:12:47Z")

</div>

Heesob Park wrote in post #1113488:

> Hi,
> 
> > ========================  
> > 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](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](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  
> &nbsp;&nbsp;extend FFI::Library  
> &nbsp;&nbsp;ffi\_lib FFI::Platform::LIBC  
> &nbsp;&nbsp;attach\_function :\_putch, [:int], :int  
> end
> 
> def put\_cc car  
> &nbsp;&nbsp;&nbsp;&nbsp;MyLib.\_putch(car)  
> end
> 
> # 'hola'.each\_byte { |i| put\_cc i }
> 
> Regards,  
> Park Heesob

- - - -

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.

> **···**
>
> > 2013/6/25 jf Baillon \<lists@ruby-forum.com\>:
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
