Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

How to know if an application is completely launched

by juo (Curate)
on Oct 04, 2004 at 09:43 UTC ( #396166=perlquestion: print w/replies, xml ) Need Help??
juo has asked for the wisdom of the Perl Monks concerning the following question:

I was wondering if their is an easy way to know if a Windows application is up and running or not. When I use Win32 to launch an executable the Perl script will continue after that which is ok, however some code in it will communicate with the application and if the application is not completely running it will fail. A way to get around that was by using sleep(4), but this is so dirty, because on some systems it take 3 seconds to launch, on others longer and if launched second time it only take 1 second, so the script would be all the time waiting for nothing. Is their a way to let the script wait untill the application is fully up and running.

Win32::Process::Create($get,$GENESIS_EDIR.'\\get\\get.exe',"get -a$p +ort",0,CREATE_NEW_CONSOLE,".")|| die ErrorReport();

Replies are listed 'Best First'.
Re: How to know if an application is completely launched
by PodMaster (Abbot) on Oct 04, 2004 at 12:47 UTC
    It really depends on what you mean by fully up and running, but if you control both applications, what you want to do is use Win32::Event objects. That way you sleep only until your new process is up and running (until it sends you a signal). Another approach is to sleep until a certain file/directory is created
    select undef, undef, undef, 0.5 while ! -e '/file/get.exe/will/create/once/its/fully/up/and/runnin +g';
    If you don't control get.exe, well then the application may be fully up and running when it creates a window, so you just sleep until you can find a window for get.exe.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      Thanks for the hint, that was all I need. I knew their is some function to get all the active windows and checking those windows does the job. Works very nice. Below my code for reference

      # Used to focus windows on the top use Win32::GuiTest qw(FindWindowLike GetWindowText SetForegroundWindow SendKeys); while ($found == 0) { $found = FindWindowLike(0, 'Engineering Toolkit', ""); sleep (4); print "Application is still starting Wait .........\n"; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://396166]
Approved by Arunbear
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2018-03-23 15:30 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (294 votes). Check out past polls.