if process.exist then . . . ???

B

Bigmac Turdsplash

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

}
 
B

Bigmac Turdsplash

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
 
S

steve

Bigmac said:
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
 
L

Lars Mai

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top