How can I handle a dialog box created by a program starting with Perl?

I have a Perl script that calls another application in which I do not control. I use system()to call this application. Sometimes this application generates an unhandled exception and creates a dialog box with exceptions that you need to listen to. Since this is a raw Perl script, I would like to detect this situation and handle it in a Perl script and continue. My search for solutions was not fruitful. Because it system()creates a child process, standard Perl exception handling mechanisms are not used. I am working on Windows XP. Any suggestions?

+3
source share
2 answers

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

At almost any time you need to interact with Windows system things, you end up using the Windows API (is there an official name for this?) Through Win32 :: OLE .

+2
source

Find the dialog box and kill it. For example, if you want to automatically kill a window called a calculator title, 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);
}
+2
source

Source: https://habr.com/ru/post/1766636/


All Articles