Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

How to continue running script if .exe program fails

by sjwnih111 (Novice)
on Sep 13, 2013 at 17:54 UTC ( [id://1053977]=perlquestion: print w/replies, xml ) Need Help??

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

I have a Perl script that calls an .exe program, but the .exe program sometimes fails. When failing, the .exe opens up a dialog that prompts the user to click "ok." When the user clicks "ok," the perl script resumes, moving on to the next piece of data that it is supposed to send to the .exe file. I would like to automatically select ok, so that, even without a user, the Perl script can continue to run if the .exe file crashes. Is this possible? I was wondering if it would be possible to just set a timer, so that if the .exe program runs for longer than 10 minutes, the perl script would kill it--whether it gives the pop-up or not (would it also kill it if it gave a pop-up?)\ Thanks again.
  • Comment on How to continue running script if .exe program fails

Replies are listed 'Best First'.
Re: How to continue running script if .exe program fails
by dasgar (Priest) on Sep 13, 2013 at 21:30 UTC

    I'm assuming that the reference to "an .exe program" and your description of what I call a pop up window would indicate that you're on a Windows system. Is that correct?

    If so, the answer to your question is yes. Here's how I would approach this task:

    • start a new thread that will do the task of calling the .exe program
    • have a while loop checking to see if the thread is joinable
      • check to see if the pop up window exists
      • if the pop up window exists, automate the response
    • join the thread
    • repeat the above steps for any subsequent .exe calls

    For the window automation, you can use Win32::GuiTest. It will have functions that will help you find the pop window and to interact with it (mouse clicks, keystrokes). My recommendation would be to use keystrokes rather than mouse clicks with the Win32::GuiTest stuff.

    Another alternative to the Win32::GuiTest would be to use AutoIt. In that case, you would create an AutoIt script and then either call that script from your Perl code or make your AutoIt script an .exe program and call that from your Perl code.

    Personally, I would recommend sticking with Win32::GuiTest rather than using AutoIt. However, you might find it useful to get AutoIt for its AutoIt Window Info Tool, which can be used to get information about the windows that you are trying to automate.

Re: How to continue running script if .exe program fails
by Anonymous Monk on Sep 14, 2013 at 01:47 UTC
Re: How to continue running script if .exe program fails
by zork42 (Monk) on Sep 16, 2013 at 04:39 UTC
    However, you might find it useful to get AutoIt for its AutoIt Window Info Tool, which can be used to get information about the windows that you are trying to automate.
    I use http://www.catch22.net/software/winspy-17 to find the info I need (normally the Window Class, and the Window's title).
    (Or you might already have the Spy++ utility that ships with Microsoft Visual Studio.)

    Then you call Win32::GuiTest's FindWindowLike() to get a handle to the window. Then you can manipulate the window.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-23 14:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found