Launch an application and continue the script's execution

Tim Golden mail at timgolden.me.uk
Wed Aug 27 11:02:52 CEST 2008


Gabriel Genellina wrote:
> Start the application in a separate console (using `start "" bat_file` 
> might be the easiest way) and then, within your Python script, wait 
> until the new process is ready. The wmi module by Tim Golden can help 
> <http://tgolden.sc.sabren.com/python/wmi.html>
> e.g. wait until Microsoft Word opens:
> 
> import wmi
> c = wmi.WMI()
> while not len(c.Win32_Process(name="winword.exe")):
>     sleep(500)

Just for information's sake, you can do this
a little more neatly in WMI:

<code>
import wmi

c = wmi.WMI ()
word_watcher = c.Win32_Process.watch_for (name="winword.exe")
winword = word_watcher ()

</code>

Actually, now I look it's not that much neater; it basically
pushes the polling into WMI itself. Still, it is at least an
alternative :)

TJG



More information about the Python-list mailing list