AutomateWithPerl has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, I do some nice GUI testing in my employment and ran into a strange problem recently. I was wondering if anyone else has seen this? I recently found a band-aid solution that seems to be doing just fine. Here is the deal: I am using ActivePerl on a windows XP machine, and have a perl script launch a GUI and do some testing on it, like so...
... # launch the window $pid = fork; unless( $pid ) { `MyGUI.exe`; exit 1; } # much code to manipulate the GUI, etc here.. # now close the GUI.. &PressAButton( $gui_handle, "&Close" ); # should be done here
Looks pretty simple, huh? The problem: When the GUI exits, the child process gets screwed up somewhere and crashes. I then either get a popup that perl.exe has tried to write to mem location 0x0, or I get some nice popup that informs me that Perl has crashed, and would I like to send a nice note to M$. My previous solution: Since only the child process has crashed, I use the parent process to wait for these annoying popups and deal with them. This solution did not work when we started testing in evil Windows 7. Instead, both processes would lock up, thereby preventing me from dealing with the popup. After pulling what's left of my hair out the last few days, I came upon a band-aid solution:
... # launch the window $pid = fork; unless( $pid ) { `MyGUI.exe`; exit 1; } sleep 10; # long enough for the GUI to launch # here is the kicker: kill 9, $pid; # now continue with my usual testing...
Has anyone encountered this before? Are there any dire affects to killing my process? Thanks in advance.

Replies are listed 'Best First'.
Re: A solution to a pretty fork()ed up problem with GUI testing
by BrowserUk (Patriarch) on Oct 17, 2010 at 03:15 UTC

    Try replacing the fork and backticks with:

    system 1, 'MyGUI.exe';

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: A solution to a pretty fork()ed up problem with GUI testing
by eyepopslikeamosquito (Archbishop) on Oct 17, 2010 at 04:28 UTC

    Your use of fork and backticks in harness with a "sleep 10/kill 9 bandaid" just to launch a GUI process asynchronously is truly gut-wrenching. BrowserUk's advice of using the Win32 system(1, @args) trick is far superior and likely to be adequate for your purposes. Unfortunately, as far as I'm aware, this handy Win32 trick is documented only in perlport and so is not as well known as it should be.

    For more Win32-specific control of processes, see the Win32::Process and Win32::Job modules.

      Thanks, both, for the advice. The system trick works perfect for what we need. Again, too bad this is not more well known.