You can modify the Perl script, right? One thing you might try is to modify it so that it doesn't keep starting new Excels, but reuses the already running one.
Win32::OLE->GetActiveObject("Excel.Application"); should take care of this. To create the excel object you would use something like this:
use Win32::OLE;
use Win32::Semaphore;
$excel = Win32::OLE->GetActiveObject("Excel.Application");
if (!$excel) {
print "Not found, locking\n";
my $sem = Win32::Semaphore->new(1, 1, 'ASGdailyreport_StartExcel')
+;
$sem->wait();
print "locked, looking again\n";
$excel = Win32::OLE->GetActiveObject("Excel.Application");
if (!$excel) {
print "still not found, starting\n";
$excel = Win32::OLE->new('Excel.Application') or die "oops\n";
# or
# $excel = Win32::OLE->new('Excel.Application','Quit') or die
+"oops\n";
# if you wish the Excel to quit once the last script using it
+exits
}
$sem->release();
print "unlocked\n";
}
if (!$excel) {
die "Could not connect to or start MS Excel!\n";
}
print "have an excel $excel\n";
I'm not sure though whether Excel handles two controling applications correctly, you would have to try that.
If it doesn't you might try to change the script into a service (see Win32::Daemon or Win32::Daemon::Simple) and control it either via Semaphores and a named pipe or by creating a file containing the parameters in a specific directory. The second might be easier to do from the ASP, you could create the file and redirect to a page that will check whether the report is ready (file appears in the finished reports directory) and either say something like "The report is being generated" and refresh in a few seconds or redirect to the report. Do I make sense?
Actually you might try if this tiny script doesn't solve the issue. It tries to connect to the running Excels and (if things work right) would close them if there is no other program referencing them. Not sure it would work, but it's worth a try:
use Win32::OLE;
my $i = 0;
while (1) {
my $excel = Win32::OLE->GetActiveObject("Excel.Application");
last unless $excel;
print "Found an excel\n";
last if ++$i > 10;
print "Let's see ($i)\n";
}
Jenda
|
XML sucks. Badly. SOAP on the other hand is the most powerfull vacuum pump ever invented. |
|