DVCHAL has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I am trying to extract the some information from the group of docx file. So I first convert the docx to text file using Win32::OLE. The problem is when I have to run the program Second time, I have to close the "Winword.exe" manually from taskmanager. I suspect its clearly because we are not closing the Word Application in script properly. Below is the code snippet, any help on to close the Word application would be greatful.
open(OUTFILE2,">Author_name_extract.txt") or die("Cant open Output fil +e\n"); @filesnames = glob '*.docx'; foreach $count (@filesnames) #Loop till the end is reached { $filename = "D:\\MRJ_BCU\\Perl\\From thejaswini\\doc_read\\$count" +; $document = Win32::OLE -> GetObject($filename); my $app = $document->{Application}; open(OUTFILE1,">File_under_Review.txt") or die("Cant open Output f +ile\n"); print "Extracting Text from $filename...\n"; $paragraphs = $document->Paragraphs(); $enumerate = new Win32::OLE::Enum($paragraphs); while(defined($paragraph = $enumerate->Next())) { $a = $paragraph->{Range}->{Text}; print OUTFILE1 "$a\n"; } close(OUTFILE1); $#document->Close();

Replies are listed 'Best First'.
Re: To close the Word Application through WIN::OLE
by james28909 (Deacon) on Dec 12, 2014 at 07:54 UTC
    A quick look at this Win32::OLE node might help :)

    EDIT: Also the docs made it pretty clear how to open the program and close it Win32::OLE
Re: To close the Word Application through WIN::OLE
by Gangabass (Vicar) on Dec 12, 2014 at 13:28 UTC
    You need to Quit your app:
    $app->Quit;