检查程序是否 运行

Checking if a program is running

有没有办法通过 Ruby 程序找出桌面上是否 运行 程序?会不会像使用系统调用一样简单?

示例:

def find_process
  process = 'Windows'
  if process != #some system call to check the process
    #execute process
  else
    puts "Process not found"
  end
end

可能值得一提的是我是运行 OS Windows 7.

这是一个使用 tasklist 的人为示例。它将反引号系统调用的结果分配给 status 变量。如果此变量为空,则指定的程序不是 运行.

def find_process
  status = `tasklist | find "notepad.exe"`
  if status.empty?
    puts "Process is not running"
  else
    puts "Process is running"
  end
end

find_process