killing process in windows

Trent Mick trentm at ActiveState.com
Thu Jun 9 11:29:58 EDT 2005


[Miki Tebeka wrote]
> Hello Veronica,
> 
> >    I am using Trent's process.py but I have a problem with killing the
> >    processes in windows.
> >    For example :
> > 
> >    import process,time
> > 
> >    p=process.ProcessOpen('C:\Program Files\Windows Media
> >    Player\wmplayer')
> >    time.sleep(3)
> >    p.kill()
> > 
> >    will start Media Player without terminating it.
> >    Any suggestions?
> A brutal way will be to use win32process.TerminateProcess (from win32all
> package - http://starship.python.net/crew/mhammond/).

Miki, actually my process.py *is* using TerminateProcess under the hood
here.

Veronica,
Sorry, I really don't know what might be causing the problem here. Does
your little snippet work properly for other applications like, say,
Notepad, iexplore.exe, Word?

Note that I'm am going to put the path in a list to be sure that the it
gets quoted properly. It *might* be correct as just a string (as you had
it) but I'd have to check.

If you do this in the interactive shell (don't quit the shell):

    >>> import process
    >>> p = process.ProcessOpen(["C:\Program Files\Windows Media Player\wmplayer"])

Does media player start? Is there a "wmplayer.exe" is the process list
(press Ctrl+Esc to open Task Manager)?

Now try this is the same interactive shell:

    >>> p.kill()

Trent

-- 
Trent Mick
TrentM at ActiveState.com



More information about the Python-list mailing list