[Tutor] # what do I do now to kill the the Windows program which has finished its work?

Alan Gauld alan.gauld at btinternet.com
Sat Apr 25 21:00:11 CEST 2009


"Ian Campbell" <ian-campbell at shaw.ca> wrote

> os.startfile("c:\\buy.exe" , 'OPEN')    # THIS WORKS  and returns but 
> does not return the taskID

Take a look at the subprocess module.

> # what do I do now to kill the  the Windows program which has  finished 
> its  work?

This is trickier, if the program does not stop itself when it finishes
then you need to look at timers and threads and how to programmatically
terminate a program in Windows. Usually the command line program
will terminate itself when done but if it doesn't you can use time.sleep()
as a delay. You will need to launch the program in a thread. You can
then try killing the thread which may kill the program, or if not, use the
Windows API to kill the program (gets messy). This is easier on Unix
in my experience!

HTH

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/





More information about the Tutor mailing list