i8igmac
1
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
}
i8igmac
2
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
i8igmac
3
Bigmac T. wrote:
pids.push(s.pid) if s.cmdline =~ /calc/
}
if pids.length.zero?
puts ‘calc not running’
else
puts ‘calc is running’
end
i8igmac
4
On Wed, Sep 30, 2009 at 12:50 PM, steve [email protected] wrote:
if pids.length.zero?
if pids.empty?
martin
i8igmac
5
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,