On 12/19/2011 08:32 AM, Alex Young wrote: > I'm porting some code from Linux to Windows which relies on direct > access to a CD's block device. This "just works" on Linux if I > File.open("/dev/cdrom"), but I can't see how to make it work on Windows. > > While manually running a dl/imported CreateFile works and gives me a > valid handle, just running File.open("\\\\.\\D:", "r") crashes the > interpreter (1.9.3-p0), as does IO.sysopen. > > Is there a built-in way to turn an open handle into a File object? I > blindly tried IO.for_fd, but that fails and I got no further. I'm not expert on this, but my quick look in MSDN seems to indicate that you need to use DeviceIoControl to handle reads and writes to the device handle once you get it from CreateFile: http://msdn.microsoft.com/en-us/library/windows/desktop/aa363216%28v=vs.85%29.aspx Regular files wouldn't be accessed using that function, so that's probably why Ruby chokes on file objects you create with those special device paths. If you want the object you may eventually create in Ruby to work mostly like an IO object, take a look at my io-like gem: https://rubygems.org/gems/io-like Unfortunately, it doesn't support the Ruby 1.9 IO API yet, but it should get you the basics without a ton of work. :-) -Jeremy