Trouble killing a process on windows

reed reedobrien at gmail.com
Sat Jun 2 18:30:45 EDT 2007


On Jun 2, 12:27 pm, Thomas Nelson <t... at mail.utexas.edu> wrote:
> Hi, I'd like to start a program, run it for a while, then terminate
> it.  I can do this on linux, but I'm new to working with windows.
> Here's my script:
>
> from subprocess import Popen
> from time import sleep
> import win32api
> war3game = Popen(["C:\Program Files\Warcraft III\Frozen Throne.exe"])
> sleep(30)
> print "slept for 30"
> print win32api.TerminateProcess(int(war3game._handle),-1)
> #print
> ctypes.windll.kernel32.TerminateProcess(int(war3game._handle),-1)
> print "terminated process"
>
> Here's the output:
> slept for 30
> Traceback (most recent call last):
>   File "C:\Python24\warcraft\runwar3.py", line 7, in ?
>     print win32api.TerminateProcess(int(war3game._handle),-1)
> error: (5, 'TerminateProcess', 'Access is denied.')
>
> I'm logged in as adminstrator.  Does anyone know how to fix this
> problem?
> Thanks for your time,
> Tom

kill = Popen(['taskkill', war3game.pid])

*shrugs*

maybe it is just taskill, or maybe you need the full path.
don't recall as I quit using windows.

Takskill on XP and newer maybe




More information about the Python-list mailing list