im trying to monitor a process, if this process is closed then i want to
write a time and date to a logfile...
i dont know how to do it but it should be as simple as this...
(improper)
loop {
if process.exist('notepad.exe') then
puts 'notepad exist'
else
my_file = File.new("c:\log.txt", APPEND)
my_file.puts "here is the time add date, notepad has been killed"
end
}
···
--
Posted via http://www.ruby-forum.com/.
Here is what i have so far... i have been playing with this for a while
now... im getting no were ,-(
require 'rubygems'
require "win32/process"
require "sys/proctable"
include Sys
pids = []
ProcTable.ps{ |s|
pids.push(s.pid) if s.cmdline =~ /calc/
}
if calc exist # this is improper, so how do i make it proper?
puts 'calc is running'
else
puts 'calc not running'
end
···
--
Posted via http://www.ruby-forum.com/.
steve9
(steve)
3
Bigmac Turdsplash wrote:
Here is what i have so far... i have been playing with this for a while now... im getting no were ,-(
require 'rubygems'
require "win32/process"
require "sys/proctable"
include Sys
pids =
ProcTable.ps{ |s|
pids.push(s.pid) if s.cmdline =~ /calc/
}
if pids.length.zero?
puts 'calc not running'
else
puts 'calc is running'
end
Lars_Mai1
(Lars Mai)
4
pids =
ProcTable.ps{ |s|
pids.push(s.pid) if s.cmdline =~ /calc/
}
How about this:
calc_is_running = ProcTable.ps.any? {|pinfo| pinfo.cmdline =~ /calc/ }
# returns true or false
or if you need the pid of the process later on:
calc_processes = ProcTable.ps.select {|pinfo| pinfo.cmdline =~ /calc/ }
# returns an array of matching processes
if calc_processes.empty? .... else ...
hth,
- Lars
···
--
Posted via http://www.ruby-forum.com/\.