From: Charles Calvert Date: 2010-10-20T10:30:18+09:00 Subject: Re: Open a windows device file handle in ruby? On Thu, 7 Oct 2010 11:43:29 -0500, Qaz Qaz wrote in <03eb127d240a2c02e355181af176281f@ruby-forum.com>: >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! 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). -- Charles Calvert Moderator - alt.computer.consultants.moderated Submission Address: accm@celticwolf.net Contact Address: accm_mod@celticwolf.net