views:

69

answers:

2

I have a Perl script that calls another application I don't have control over. I use the system() to call this application. On occasion, this application generates an unhandled exception and puts up an exception dialog box that needs to be attended to. Since this is an unattended Perl script, I would like to detect this situation and handle it within the Perl script and continue on. My search for solutions has not been fruitful. Since system() generates a child process, the standard exception handling mechanisms in Perl do not apply. I am running on Windows XP. Any suggestions?

+2  A: 

Perhaps the Perlmonks post Win32::OLE: how to call Excel VBA macros and catch all VBA errors without dialog boxes appearing? can help.

Almost any time that you have to interact with Windows system things, you're going to end up using the Windows API (is there an official name for that?) through Win32::OLE.

brian d foy
+2  A: 

Find the dialog box and kill it. For example, if you want to automatically kill a window that thas the title of Calculator, the following script should work.

use strict;
use warnings;
use Win32::GUI();

use constant WM_CLOSE => 16;


sub kill {
    my $handle = Win32::GUI::FindWindow('', 'Calculator');
    Win32::GUI::SendMessage($handle, WM_CLOSE, 0, 0); 
}

while(1){
    &kill;
    sleep(5);
}
Mike