if process.exist then . . . ???

Discussion in 'Ruby' started by Bigmac Turdsplash, Sep 30, 2009.

  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

    }
    --
    Posted via http://www.ruby-forum.com/.
    Bigmac Turdsplash, Sep 30, 2009
    #1
    1. Advertising

  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
    --
    Posted via http://www.ruby-forum.com/.
    Bigmac Turdsplash, Sep 30, 2009
    #2
    1. Advertising

  3. Bigmac Turdsplash

    steve Guest

    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
    steve, Sep 30, 2009
    #3
  4. On Wed, Sep 30, 2009 at 12:50 PM, steve <> wrote:
    >
    > if pids.length.zero?


    if pids.empty?

    martin
    Martin DeMello, Sep 30, 2009
    #4
  5. Bigmac Turdsplash

    Lars Mai Guest

    > 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/.
    Lars Mai, Sep 30, 2009
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jona
    Replies:
    2
    Views:
    802
  2. Y.S.
    Replies:
    3
    Views:
    1,011
    strajan
    Sep 17, 2003
  3. empriser
    Replies:
    1
    Views:
    637
    Ian Collins
    Mar 6, 2007
  4. Replies:
    0
    Views:
    273
  5. Victor Hooi
    Replies:
    1
    Views:
    133
    Nobody
    Feb 10, 2013
Loading...

Share This Page