nico7nibor has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: To end process in windows
by dasgar (Priest) on Aug 10, 2010 at 05:19 UTC | |
|
Re: To end process in windows
by sam_bakki (Pilgrim) on Aug 10, 2010 at 10:02 UTC | |
|
Re: To end process in windows
by GrandFather (Saint) on Aug 10, 2010 at 02:49 UTC |