Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

detecting activities of scripts

by blackadder (Hermit)
on May 13, 2004 at 16:04 UTC ( [id://353121]=perlquestion: print w/replies, xml ) Need Help??

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

Dear and beloved monks, greetings to you of the highest order.

Ouch, it has been a long day and sorry for the title of this post.

Question: Is there away that I can detect whether a script that I call from within my Perl script has triggered a win32 message box?

The reason is, I am calling a number of 'GO' scripts or (.exe)s from within my Perl script. All those scripts are software installation programs. Some will install successfully and some - I suspect - will not. The ones that will NOT install successfully will display a windows massage indicating a failure has occurred. The text in this windows message box is standard text (i.e. appears when ever a Go script fails) and always display the critical red cross sign. Basically I need to detect this activity and flag the scripts that have failed. Simple!!

Thanks

Replies are listed 'Best First'.
Re: detecting activities of scripts
by Ven'Tatsu (Deacon) on May 13, 2004 at 16:21 UTC
    Win32::GUITest should work, it can identify windows based on title (among other criteria) and, if it needed, send them keystrokes like enter or escape to close them.
      Yep, I think this will work, however not sure how!

      This is the code that I have done so far
      #! c:\perl\bin $|++; use strict; use Win32; use Win32::GuiTest qw(FindWindowLike GetWindowText SetForegroundWindow + SendKeys); use vars qw /%data/; $Win32::GuiTest::debug = 0; # Set to "1" to enable verbose mode $data{apps_list} = shift @ARGV; $data{host} = Win32::NodeName(); system (cls); print "\nThis machine is ". $data{host}; print "\n\nPath to apps list => ". $data{apps_list}."\n"; open (LST, "$data{apps_list}") || die "$! : File was not found\n"; chomp (@{$data{Go_scripts}} = <LST>); for my $item (@{$data{Go_scripts}}) { print "\n$item\n"; system ($item); my @win =FindWindowLike(0, "^Go", ""); for (@win) { print "$_>\t'", GetWindowText($_), "'\n"; SetForegroundWindow($_); ); } #print "$^E, $!\n".Win32::FormatMessage(Win32::GetLastError()); Win32::AbortSystemShutdown($data{host}); print "\nDone\n"; }
      System($item) will run the 'Go' scripts for me, I would only get a windows message box if the installation was NOT successfull. Other than that I do not get a confirmation of successfull installation. So, if the installation did not begin, then a message box appears titled GO, and starts with the string "the Go script did not start due to...."

      Can someone please show me how can I detect that this window has popped up? and be able to send a mouse click to the ok button in that message box so the script can continou?

      TIA
Re: detecting activities of scripts
by tachyon (Chancellor) on May 13, 2004 at 16:45 UTC

    One practical approach might be to start your software install programs with their silent flag and look for the exit code (assuming you are using system to fire them up). Another approach is to start the installers with Win32::Process You can then SetPriorityClass, Wait, GetExitCode and Kill them if they have not successfully exited after a sufficiently long period determined by you in the Wait.

    cheers

    tachyon

      Yep, InstallShield apps almost always can be fed a setup.iss file to make them install silently. Running GUI ("is this on my screen") checks is definitely hackish, wouldn't go there. If setup.iss doesn't work for one or more of your programs, I'd suggest you see if you can get them fixed, as this isn't your problem, but a problem with those installers.
Re: detecting activities of scripts
by kvale (Monsignor) on May 13, 2004 at 16:19 UTC
    I suppose you could create a snapshot of the screen and do some image processing to detect a red cross, but that seems like a lot of work.

    An easier alternative would be to read an install log, if the exe's produce them, looking for alerts or failures. Another possibility is to set an alarm and timeout if an app does not complete after a preset interval.

    -Mark

Re: detecting activities of scripts
by dragonchild (Archbishop) on May 13, 2004 at 16:21 UTC
    Take a look at the difference between wscript and cscript as your calling mechanism. If you must, a timeout is prolly your best option.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

    I shouldn't have to say this, but any code, unless otherwise stated, is untested

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://353121]
Approved by davido
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-25 15:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found