require "win32/open3"
input, out, err, pid = Open4.popen4(command)
...
Process.kill(pid)
Regards,
Dan
···
-----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
awesome! so can do something like this from now on to make code
semi-portable?
begin
require 'open4'
rescue
require "win32/open3"
end
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.
thanks tons!
-a
···
On Tue, 24 May 2005, Berger, Daniel wrote:
require "win32/open3"
input, out, err, pid = Open4.popen4(command)
...
Process.kill(pid)
Regards,
--
email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
My religion is very simple. My religion is kindness.
--Tenzin Gyatso
===============================================================================
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
but maybe
child.wait #=> Process::Status
i have code that does just that. the reason for open4 is just to provide a
toolset for coding the above 
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?
regards.
-a
···
On Thu, 26 May 2005, nobuyoshi nakada wrote:
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.
--
email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
My religion is very simple. My religion is kindness.
--Tenzin Gyatso
===============================================================================
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