Open a windows device file handle in ruby?

Hello, I have windows device driver which creates a symbolic link for
the path ‘\.\MyDevice’. In C I can then use CreateFile() to open this
device, e.g.

—[c
snippet]------------------------------------------------------------------
handle = CreateFile( “\\.\MyDevice”, GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL );

WriteFile( handle, data, len, &written, NULL );

CloseHandle( handle );
—[c
snippet]------------------------------------------------------------------

However in Ruby, I should be able to simple use something like:

—[ruby
snippet]---------------------------------------------------------------
handle = open( “\\.\MyDevice”, File::RDWR )
handle.syswrite( data )
handle.close
—[ruby
snippet]---------------------------------------------------------------

but it does not work and segfaults the ruby interpreter during the open!

Can anybody please help as to what I am doing wrong. How do you open a
file handle to a device in windows?

Thanks!

On Thu, 7 Oct 2010 11:43:29 -0500, Qaz Q. [email protected]
wrote in [email protected]:

handle.close
—[ruby
snippet]---------------------------------------------------------------

but it does not work and segfaults the ruby interpreter during the open!

Your assumption that you should be able to use standard Ruby IO
functions seems suspicious to me. What happens if you write C code
that attempts to open the file using fopen() and write to it with
fputs()? If that fails, then you have your answer.

Instead, you could call the Win32API functions CreateFile() and
WriteFile() from Ruby using either the Ruby Win32API library or
dl/win32 (see
http://stdlib.rubyonrails.org/libdoc/dl/rdoc/classes/Win32API.html#M000496).