Launch an application and continue the script's execution
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Tue Aug 26 01:41:05 EDT 2008
--- El lun 25-ago-08, Marian Popa <marian_popa2003 at yahoo.com> escribió:
Please keep posting on the list.
Have you tried what other people already suggested?
> - I need to access a bat file which opens an application
> that doesn't have COM interface in order to control it
> from Python; so I just need to access that bat file and
> inside it there are several commands for this application
> - the bat file is correct because if I manually open it
> (double click), it is working fine
> - the problem is that when I run the script, the bat
> file is opened somehow (I can see the command prompt), but
> the application is not opened unless the script is finished
> - please see the 3 attached files (script, bat file and a
> test Word document): the doc is opened only after the cript
> execution finishes
> - in my test, the next lines after the call of the batch
> file are dependent on the succesfull open of that
> application; otherwise, the whole script crashes
> - what is interesting is that if I put a breakpoint on the
> line in which I access the batch file, and I step on it
> manually, the application launches correctly and then
> the script is working fine, but this is not an automated
> solution
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)
> P.S. The application that I need to open must run in the
> background during the execution of the rest of the script.
> At the end, I need to close it. Is it possible to do this
> with a script command?
Do you *have* to start it using a batch file? If you start the application
within Python --using subprocess.Popen by example-- you can obtain its
pid, and later kill it (with os.kill)
--
Gabriel Genellina
More information about the Python-list
mailing list