Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > if process.exist then . . . ???

Reply
Thread Tools

if process.exist then . . . ???

 
 
Bigmac Turdsplash
Guest
Posts: n/a
 
      09-30-2009
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/.

 
Reply With Quote
 
 
 
 
Bigmac Turdsplash
Guest
Posts: n/a
 
      09-30-2009
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/.

 
Reply With Quote
 
 
 
 
steve
Guest
Posts: n/a
 
      09-30-2009
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
 
Reply With Quote
 
Martin DeMello
Guest
Posts: n/a
 
      09-30-2009
On Wed, Sep 30, 2009 at 12:50 PM, steve <(E-Mail Removed)> wrote:
>
> if pids.length.zero?


if pids.empty?

martin

 
Reply With Quote
 
Lars Mai
Guest
Posts: n/a
 
      09-30-2009
> 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/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Slow, then quick then slow JosephByrns ASP .Net 4 11-13-2007 01:34 AM
Help. SessionID is x then y then x then y BodiKlamph@gmail.com ASP General 0 09-03-2005 03:02 PM
Read all of this to understand how it works. then check around on otherRead all of this to understand how it works. then check around on other thelisa martin Computer Support 2 08-18-2005 06:40 AM
greater then / less then =?Utf-8?B?TWlrZQ==?= ASP .Net 2 11-04-2004 06:05 PM
Help: anyway to burn movie to DVD RW (then view it) and then eraseafterward? qwerty DVD Video 6 01-07-2004 04:54 AM



Advertisments