Hi,

Sorry about not being able to explain my problem clearly. I have a script that retrieves word reports from two countries. The script is run in a remote machine. The script gets the word files, opened them, copy contents then merge it into a single word report. Somehow when a single employee is not able to properly close his doc, the script stops and is not able to continue. Thus winword.exe crashes.

I would like to know what would be the best way to check if winword.exe process have been idle, and kills them or skip that single word opened, free memory and help the app get back on track on the script.

i have this method that i used:

sub KillWinWord { print "Closing Application... -> "; my $flag = 0; @temp = `tasklist.exe /FI "STATUS eq running"`; foreach $temp (@temp) { if ($temp =~ WINWORD) { $flag = 1; } } if ($flag == 1) { $t = `taskkill /IM "WINWORD.EXE"`; print "$t"; } else { print "WORD handle is closed..."; } print "\n\n"; }

I placed this after processing the report file from a working directory

foreach $key (sort (keys(%SReport_Hash))) { # Lets get first Name out from the key $key =~ s/\\\\//g; @key_value_chunks = split(/\\/,$key); $SReport_Name = $key_value_chunks[5]; open WordDocHandleCountry1, ">> $SReport_Country1"; open WordDocHandleATLCountry2, ">> $SReport_Country2"; $key = '\\\\' . $key; # Changing $key to real path &Read_Document($key, \*WordDocHandleCountry1, \*WordDocHandleCountry +2, $SReport_Name, 1); &KillWinWord(); }

Thanks for the time reading this.

Note: I kinda updated and ruined my first post,sorry


In reply to To end process in windows by nico7nibor

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.