From: "Berger, Daniel" Date: 2005-05-24T23:56:00+09:00 Subject: Re: Killing a Process started with Kernel.system > -----Original Message----- > From: Ara.T.Howard@noaa.gov [mailto:Ara.T.Howard@noaa.gov] > Sent: Tuesday, May 24, 2005 8:20 AM > To: ruby-talk ML > Subject: Re: Killing a Process started with Kernel.system > > > On Tue, 24 May 2005, Gavin Kistner wrote: > > > On May 23, 2005, at 11:40 PM, Martin aus Chemnitz wrote: > >> Under Windows, I want to start an external program and kill it on > >> exitting my Ruby script. > >> > >> begin > >> $t = Thread.new { system("everlasting") } > >> ... > >> ensure > >> $t.kill > >> end > >> > >> does not stop the everlasting program, it stops $t, not its child > >> processes. Such a command is urgently needed! > > > > Here's a way to kill any process using Win32OLE: > > > > require 'win32ole' > > > > class WIN32OLE > > def to_a > > a = []; self.each{ |p| a<

> end > > end > > > > # Find the process for the player > > mgmt = WIN32OLE.connect('winmgmts:\\\\.') > > process = mgmt.InstancesOf("win32_process").to_a.find{ |proc| > > proc.name =~ /myapp.exe/ } process.Terminate > > so no way by pid? > > -a require "win32/open3" input, out, err, pid = Open4.popen4(command) ... Process.kill(pid) Regards, Dan