SPUG: Not reading to end of binary file on the PC
ced at carios2.ca.boeing.com
ced at carios2.ca.boeing.com
Mon May 7 16:40:27 CDT 2001
> The script reads a proprietary binary file and gets different results
> between a sun/solaris environment (PERL ver. 5.6.0) and Windows 2000
> environment (ActiveState build 522 and build 623). The code works perfectly
> on the Unix box (reads in all the file and formats it to a text file) but
> only part of the binary log file is read when using Win2000 (the required
> OS). A section of relevant pseudo code is below. When running on the PC,
> the script reads the 12 fixed bytes until the last line which returns only
> 11 bytes. This is when it encounts the hex code 001a 4e00 for the first
> time on all three sample files. 001a are the 11th and 12 bytes. read()
> returns up to and including the first 00 (ASCII NULL) but doesn't read the
> 1a as it should (ASCII substitute -- what does a substitute do?).
>
> What is happening here and how do I get the script to read the whole file on
> the Windows platform?
'read' should be OK as long as not mixed with 'sysread' on the
same filehandle. Also, make sure STDOUT is set to binmode too.
Here's a bit of W2K code that reads past the EOF in
"1a 4e00", as expected:
#!perl -w
use strict;
open(B, ">./bin.tmp") or die $!;
binmode B;
my $packed = pack "I2", 0x001a, 0x4e00;
print B $packed;
open(B, "./bin.tmp") or die $!;
binmode B;
read B, my($buf), 12;
binmode STDOUT;
printf STDOUT "%x %x\n", unpack "I2" => $buf;
__END__
hope this helps,
--
Charles DeRykus
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
More information about the spug-list
mailing list