Launch an application and continue the script's execution

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sun Aug 24 06:18:09 CEST 2008


En Fri, 22 Aug 2008 07:16:40 -0300, Marian Popa <marian_popa2003 at yahoo.com> escribió:

> Hello,
> I am new in Python programming and I have the following problem:
> I have a script in which I need to open an application (called from a batch file - "trace.bat"). For this purpuse, I'm executing the following piece of code:
>  
> import os, win32process
> from win32api import Sleep
> from ctypes import windll, c_double
> amt = windll.LoadLibrary("D:\\Marian\\Proiecte\\AMT\\Libs\\AMT_Temp_DLL.dll")
> amt.InitUIForDLL()
> amt.SetKL30()
> Sleep(1000)
> amt.SetKL15()
> Sleep(1000)
>
> os.chdir("D:\\Marian\\Proiecte\\AMT\\Trace")
> os.startfile("launch_trace.bat")
> #subprocess.call("D:\\Marian\\Proiecte\\AMT\\Trace\\trace.bat")
> #pr = win32process.CreateProcess(None, "D:\\Marian\\Proiecte\\AMT\\Trace\\trace.bat", None, None, 0, win32process.NORMAL_PRIORITY_CLASS, None, None, win32process.STARTUPINFO())
> print "OK!!!"
> ....
> ....
> ....
> ....
> But, when I call the "os.startfile("launch_trace.bat")" command, the program prompter appears, but the program called in the batch file is opened ONLY after the whole script has finished the execution.
> Unfortunatley, after this line there are some very important things that has to be executed in the right order. I mean, the execution of the batch file is important for the rest of the code.
> What is strange is that if I execute this code step-by-step, using the debugger, or if I put a breakpoint on the "launch_trace" line and then I step on it, everything is working fine - the Trace application is launced correctly.
> Could anyone help in this direction? I need to launch the application and after this I want to continue the execution of the script.

Do you want to execute launch_trace.bat, wait until it finishes, and only then continue executing your script?
startfile doesn't wait, but the subprocess.call line should do exactly that. Perhaps you need another Sleep call (BTW, you don't require win32api for this - time.sleep(1.5) is the same as Sleep(1500))

-- 
Gabriel Genellina




More information about the Python-list mailing list