I had the tskill operation working fine through a python script when using Python 2.7 but when I switched to 2.5 this code fails.
import os
import time
import win32com.client
os.startfile('cmd')
shell = win32com.client.Dispatch("WScript.Shell")
shell.AppActivate('Administrator:C:\Windows\System32\cmd.exe')
time.sleep(2)
shell.SendKeys('tskill java + {ENTER}')
time.sleep(2)
shell.Sendkeys('tskill javaw + {ENTER}')
#shell.SendKeys('exit + {ENTER}')
I use os.startfile to run a python script that opens and runs the application(It’s a graphics tool).
Note: The application is already running by the time this script is called, hence I don’t need to open it here.
Can some one please tell me how to close an application successfully using this or similar method on Python 2.5. Thanks for the help!
I don’t have tskill on my system, but I think it’s similar to
taskkill /F /FI "IMAGENAME eq java*". Anyway, here’s how to call a normal console application in the background (i.e. a hidden window) using the subprocess module (tested in Python 2.5.2, but usingtaskkillinstead):I used
callbecause it only matters whether the call succeeds or fails, but in general you can usesubprocess.PIPEto capture stdout and stderr usingsubprocess.Popen.Edit: How to kill a process started with the subprocess module