Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Killing a thread

0 views
Skip to first unread message

David Schulberg

unread,
Nov 22, 2009, 4:03:11 AM11/22/09
to
This code starts my application in a windows thread fine but the last
line does not kill the application that got fired up initially. How
come?

x = Thread.new do
system('app.exe')
end
sleep 10
Thread.kill(x)


David
--
Posted via http://www.ruby-forum.com/.

Marvin Gülker

unread,
Nov 22, 2009, 4:34:46 AM11/22/09
to
David Schulberg wrote:
> system('app.exe')

This starts a subprocess which cannot be killed by killing the thread.
Use Kernel#spawn (that should work on Windows, too, I think) instead and
kill the subprocess:
-------------------------------
pid = spawn("app.exe")
sleep 10
Process.kill("KILL", pid)
-------------------------------
Note that you don't need the thread anymore.

Marvin

PS: You may have a look here:
http://wiki.ruby-portal.de/Tricks#Externe_Programme_starten
;-)

David Schulberg

unread,
Nov 22, 2009, 7:55:39 PM11/22/09
to
Doesn't work on Windows.

irb(main):004:0> $pid = spawn('tftpd32.exe')
NoMethodError: undefined method `spawn' for main:Object
from (irb):4

Thought I needed popen4 but that gem didn't make any difference.

Marvin Gülker

unread,
Nov 23, 2009, 8:41:33 AM11/23/09
to

Oh, sorry. It's some time ago since I last worked with processes on a
Windows system. You then may have a look at the win32-process gem from
the win32-utils project: http://rubyforge.org/projects/win32utils/

Hope that helps,

Marvin

0 new messages