views:

94

answers:

2

For example, to have rschit process excell.exe means Perl.

+1  A: 

have you tried to fire a system call to "taskkill /IM excel.exe" ?

cxnull
+1  A: 

If this is about the process remaining around in "server mode" after automation, you can just call the quit method on the application object. I edited by answer at http://stackoverflow.com/questions/3751403/how-can-i-run-a-macro-in-an-excel-file-i-open-with-perl/3751790#answer-3751790 to include that. (You know, I thought if I told you that it was an Application object, you could read the MS documentation on that object to figure out what you wanted to do. )


However, you can kill a process in windows with taskkill.exe. You can read up by typing taskkill /? on the command line. It will handle taskkill /IM excel.exe.

But if you want a specific PID, you need to use tasklist.exe. (Type tasklist at the command prompt to see the output. Or tasklist /? for more information.)

The code below uses both:

use strict;
use warnings;
use English qw<$OS_ERROR>;
use File::Spec;

my $sys32dir = File::Spec->catfile( $ENV{SYSTEMROOT}, 'System32' );
my $tasklist_exe = File::Spec->catfile( $sys32dir, 'tasklist.exe' );
my ( $excel_line ) = grep { /^excel.exe\b/i } `$tasklist_exe`;
# $excel_line: 'EXCEL.EXE  4468 Console  1  20,968 K

# The PID is the second column
my ( undef, $pid ) = split qr{\s+}, $excel_line;

if ( my $rc = system( File::Spec->catfile( $sys32dir, 'taskkill.exe' )
   , '/PID', $pid 
   )) {
    die ( $OS_ERROR + 0 ) . ' - ' . $OS_ERROR;
}
Axeman
ОК. Thank you!!!
jushlwest