From: Markus Date: 2004-09-19T12:45:56+09:00 Subject: Re: bug bytes Bill -- In addition to the code for hex dumping you just posted (which I gather is working as you'd like it to) could you post the code that _isn't_ working the way you want? Specifically, it might be instructive to see how the file is opened, set to binmode, written to, reread, and dumped, since any of these may be the source of the problem. Also: * Are you setting "$\"? * Are you using print (not puts)? * Have you tried using syswrite instead (if you try it, be sure to change _all_ writes to the file, since (IIRC) it is unbuffered). * Have you tried using write? -- Markus On Sat, 2004-09-18 at 20:21, Bill Guindon wrote: > for starters, I have my cheesy little debugger, forgive the globals, I > was too lazy to make it a class (yes, really, that lazy! yes, I know, > I just typed more than it would've taken). > > It works wonderfully tho', output below... > > # just a debugging toy atm. > $hex_idx = 0 > def show_hex(val) > val.each_byte do |byte| > print "%02x ".upcase % byte > $hex_idx += 1 > print " " if $hex_idx == 8 > if $hex_idx == 16 > print "\n" > $hex_idx = 0 > end > end > end > > Here's what it shows (which is exactly what I need): > 44 45 53 43 00 00 00 00 00 00 00 4D 00 00 00 00 > 0D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 > ^^ > > But this is what ends up in the file: > 44 45 53 43 00 00 00 00 00 00 00 4D 00 00 00 00 > 0D 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 > ^^ > > after beating my brains out on this, I think I see the problem, but > not the solution. > > The value that I'm packing is a FixNum > I'm using pack("c") which converts it to the '0D' that I need. > Printing with an @file_name.print statement to a file that's opened > with .binmode > I'm doing this on Win32 > '0D' is 13 (aka CR) > > Either Windows (most likely) or Ruby (less likely, but possible) is > generously converting my perfect little '0D' to an incredibly annoying > '0D 0A' (aka CR LF) > > any suggestions? Should I convert this somehow, and use a different > pack spec to avoid this problem?