Solved

Problem reading MS Word 2000 files as binary stream

Posted on 2002-07-23
4
309 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
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now