Solved

Problem reading MS Word 2000 files as binary stream

Posted on 2002-07-23
4
317 Views
Last Modified: 2007-12-19
I need to read MS Word 2000 files as a stream of bytes.

However, whatever I do (e.g. using read function), I get only 6 bytes. Interestingly, these bytes are the same for all files!

I have no problem reading other types of binary files, including earlier versions of Word.

What is it? Some trick of MS?
0
Comment
Question by:karnovsk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 1

Expert Comment

by:vermeylen
ID: 7171743
Hi,
The "debug" utility (still available on Windows2000!) shows that MSWord 2000 files have a "EOF" character as the 7th byte. From a command box, try:
c:\>debug myword.doc
-d
(Enter d on the "-" prompt).
An ASCII dump of the word document is printed. The first 8 characters are:
D0 CF 11 E0 A1 B1 1A E1
1A (End of File) is the seventh character...
Debugging a little bit more (enter "d" on the "-" prompt, "q" to quit) showed that the EOF character appears every  now and then in the word document.
Following script reads until EOF, prints the characters, position the pointer after the EOF character and continues until next EOF:

$pos = 0;
open(DOC, "c:\\temp\\test.doc");
while (1 == 1) {
    seek DOC, $pos, 0;
    while ($char = getc(DOC)) {
     $pos++;
     print $char;
    }
    $pos++;
    print "\nEnd of file Character found, continue? (CTRL-C to quit)\n";
    $a = <STDIN>;
}

However I have no clue when the MSWord file really reaches End of File...
Dirk
0
 

Accepted Solution

by:
karnovsk earned 0 total points
ID: 7173720
Hello Dirk,

You are right: Office 2000 files contain EOF characters.

In the meantime I have found that Perl 'binmode' function solves the problem, like that:

open WORDFILE, "<$FileSpec" || die "Can't open $FileSpec $!";
binmode WORDFILE;          # To ignore ^Z as EOF
undef $/;                  # Enable "slurp" mode
$_ = <WORDFILE>;          # Whole file now here

Thanks,

Alex
0
 
LVL 8

Expert Comment

by:davorg
ID: 9622921
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ/Refund

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

davorg
EE Cleanup Volunteer
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question