./lib/commands/util.rb in p4util-0.1.1 vs ./lib/commands/util.rb in p4util-0.1.3

- old
+ new

@@ -1,10 +1,32 @@ -require 'sys/proctable' require 'P4' +require 'osutil' module Commands def Commands.p4d_running? - !ProcTable.ps().find_all { |p| p.comm =~ /p4d/ }.empty? + list_process_names.select { |p| p =~ /p4d/ }.empty? == false + end + + def self.list_process_names + if OsUtil.osx? or OsUtil.linux? + return `ps aux | awk '{print $11}'`.split(/\n/).drop(1) + else + # TODO investigate using tasklist just for this + raise 'No support for windows just yet' + end + end + + def self.pid_for_process(process) + if OsUtil.osx? or OsUtil.linux? + line = `ps aux | awk '{print $2,$11}'`.split(/\n/).drop(1).find { |p| p =~ /#{process}/ } + unless line.nil? + return line.split('\n').first.to_i + else + return nil + end + else + raise 'NO support for windows yet' + end end def Commands.p4d_available?(port=':1666') begin p4 = P4.new \ No newline at end of file