[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Killing a Process started with Kernel.system

Berger, Daniel

5/24/2005 2:56:00 PM



> -----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<<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


4 Answers

Ara.T.Howard

5/24/2005 6:42:00 PM

0

Nakada, Nobuyoshi

5/26/2005 3:25:00 AM

0

Hi,

At Wed, 25 May 2005 03:42:13 +0900,
Ara.T.Howard wrote in [ruby-talk:143556]:
> input, out, err, pid = Open4.popen4(command)
>
> it would be great to wrap this up and get it into ruby - that way there would
> be a standard way to write portable (in some fashion) programs that spawn
> external commands. my current project, dirwatch, which watches a directory
> for events and spawns user defined actions for them needs just such a thing.

That interface feels ugly to me.

Once I thought like:

child = Process.spawn([cmd, *arg], STDIN=>input, STDOUT=>output, STDERR=>err)
Process.waitpid(child.pid)

but not sure yet.

--
Nobu Nakada


Ara.T.Howard

5/26/2005 4:59:00 AM

0

Nakada, Nobuyoshi

5/26/2005 6:16:00 AM

0

Hi,

At Thu, 26 May 2005 13:59:02 +0900,
Ara.T.Howard wrote in [ruby-talk:143660]:
> now that there is a way to get stdin, stdout, stderr, and cid on both windoze
> and *nix perhaps a package to do just that could be added to the stdlib?

To implement is easy, to design is not. :-)

--
Nobu Nakada