At Wed, 19 Oct 2005 07:44:35 +0900,
x1 wrote in [ruby-talk:161230]:
x = Thread.new { system("c:/program files/internet explorer/iexplore.exe") }
x.alive # Works
why doesnt x.kill actually "kill" internet explorer? When I think of
kill, I think of "gone" as in *nix gone.
A thread and a process spawned within it are not related.
x = IO.popen("c:/program files/internet explorer/iexplore.exe")
x.close
IO#close try to send a signal to the process, however, the
problem is no signal mechanism across processes on Windows,
unless the target has a console.
I did find a hack using wscript that id like to share:
x = IO.popen("c:/program files/internet explorer/iexplore.exe")
x.pid
=> 3672
system("wscript.exe test.vbs")
I know this is a hack but can win32api not be used to make a ruby
implementation of this?
------------------------test.vbs--------------------
strComputer = "."
Set objWMIService = GetObject _
("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where ProcessID = 3672")
For Each objProcess in colProcessList
objProcess.Terminate()
Next
-----------------------/test.vbs----------------------------
Thx again!!
···
On 10/18/05, nobu.nokada@softhome.net <nobu.nokada@softhome.net> wrote:
Hi,
At Wed, 19 Oct 2005 07:44:35 +0900,
x1 wrote in [ruby-talk:161230]:
> x = Thread.new { system("c:/program files/internet explorer/iexplore.exe") }
> x.alive # Works
>
> why doesnt x.kill actually "kill" internet explorer? When I think of
> kill, I think of "gone" as in *nix gone.
A thread and a process spawned within it are not related.
> x = IO.popen("c:/program files/internet explorer/iexplore.exe")
> x.close
IO#close try to send a signal to the process, however, the
problem is no signal mechanism across processes on Windows,
unless the target has a console.
IO#close try to send a signal to the process, however, the
problem is no signal mechanism across processes on Windows,
unless the target has a console.
Could IO#close use ExitProcess() on Windows?
OP wrote:
If another module is needed, can it be installed
via gems? Thanks guys.
or you can use a combination of sysinternals' pslist, and pskill. i
find it handy for those systems where wscript and cscript have been
disabled (like on my own w2k system)
At Wed, 19 Oct 2005 11:16:57 +0900,
dave.burt@gmail.com wrote in [ruby-talk:161280]:
> You can write the WMI script in Ruby:
>
> require 'win32ole'
> strComputer = "."
> objWMIService = WIN32OLE.connect \
> ("winmgmts:\\#{strComputer}\root\cimv2")
> colProcessList = objWMIService.ExecQuery \
> ("Select * from Win32_Process Where ProcessID = 3672")
> colProcessList.each do |objProcess|
> objProcess.Terminate()
> end
Does it work on Win9X?
No, I don't think so -- I think all of WMI is WinNT family only, but
this is a direct translation of the VBScript given.
If you're asking about my suggestion of using TerminateProcess() as an
alternative to signals to close a popen'd process in IO#close, then the
answer is yes. (TerminateProcess(), not ExitProcess() which kills the
calling process.)
replace x.to_s with pid.to_s in the kill method..
ProcessID = #{pid.to_s}"
···
On 11/9/05, x1 <caldridge@gmail.com> wrote:
for future reference to others and thanks to dave.
There was a small issue with backslashes and escapes in the example
dave gave us....
Very small prob but.. wanted to inform others who may stumble on this..
Here's what worked for me in the end:
require 'win32ole'
def start_process(command)
return IO.popen(command).pid
end
def kill_process(pid)
strComputer = "."
objWMIService = WIN32OLE.connect \
("winmgmts:\\\\#{strComputer}\\root\\cimv2")
colProcessList = objWMIService.ExecQuery \
("Select * from Win32_Process Where ProcessID = #{x.to_s}")
colProcessList.each do |objProcess|
objProcess.Terminate()
end
return "done"
end
command = "c:/program files/internet explorer/iexplore.exe"
pid = start_process(command)
puts "killing pid now (#{pid}).."
sleep 1 #probably not needed
puts kill_process(pid)
On 10/27/05, Warren Seltzer <warrens@actcom.net.il> wrote:
> You can do WMI in Ruby. There's a library already built for this.
>
> Warren Seltzer
>
> P.S. Have you ever seen such a hellacious mess as WMI?
>
>
>
>
At Wed, 19 Oct 2005 17:11:58 +0900,
dave.burt@gmail.com wrote in [ruby-talk:161338]:
If you're asking about my suggestion of using TerminateProcess() as an
alternative to signals to close a popen'd process in IO#close, then the
answer is yes. (TerminateProcess(), not ExitProcess() which kills the
calling process.)
I know about TerminateProcess(), but think it is considered
critical for general purpose, like as SIGKILL.