From: Robert Klemme Date: 2009-11-27T23:41:25+09:00 Subject: Re: Ruby byte access to disk sectors like dd does 2009/11/27 Bill Kelly : > > From: "Gary Hasson" >> >> I have been unable to find any reference to Ruby methods that provide >> raw disk access the way dd does. I frequently use the Linux utility >> program, dd, and would like to be able to do the same type of byte-level >> and sector-level access to the hard drive with Ruby. (What I am looking >> for is not file access.) Are there Ruby methods to provide this >> capability (other than having Ruby access dd)? > > [i think my previous post didn't make it to the list] > > dd if=/dev/hdb bs=512 count=1 | hexdump -C > > ...should be equivalent to... > > ruby -e 'File.open("/dev/hdb", "rb") {|io| print(io.read(512))}' | hexdump > -C Just a small remark: when using #read for reading I would prefer to also use #write for writing. It is more symmetric and It may actually be that #print does a bit more in light of i18n support in Ruby 1.9. So that would be ruby -e 'File.open("/dev/hdb", "rb") {|io| $stdout.write(io.read(512))}' | hexdump -C The more fun solution would of course be to code the hex dumping in Ruby also. :-) Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/