Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Problem reading MS Word 2000 files as binary stream

Posted on 2002-07-23
4
Medium Priority
?
319 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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

609 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