lib/after.rb in after-0.7.0 vs lib/after.rb in after-0.8.0
- old
+ new
@@ -11,24 +11,24 @@
procs_by_pid = {}
if OS.windows?
procs = WMI::Win32_Process.find(:all)
for proc in procs
- procs_by_pid[proc.ProcessId] = proc.CommandLine.to_s + proc.Name.to_s
+ procs_by_pid[proc.ProcessId] = proc.CommandLine.to_s + ' ' + proc.Name.to_s
end
else
- a = `ps -ef`
+ a = `ps -ef` # my linux support isn't very good yet...
a.lines.to_a[1..-1].each{|l| pid = l.split(/\s+/)[1]; procs_by_pid[pid.to_i] = l}
end
good_pids = []
for pid, description in procs_by_pid
if description.contain?(many_args)
next if pid == Process.pid
good_pids << [pid, description]
if $VERBOSE
- pps 'adding', pid, description
+ pps 'found', "% 5d" % pid, description
end
end
end
good_pids
end
@@ -48,29 +48,33 @@
WaitPid.wait_nonchild_pid pid
end
# main, really
def self.go
- if ARGV[0] == '-v'
- ARGV.shift
+ if ARGV.delete('-v')
$VERBOSE = true
puts 'running in verbose mode'
end
- if ARGV[0] == '-l' || ARGV[0] == '--list'
- $VERBOSE = true # so it'll output the names...
+ if ARGV[0].in? ['-l', '--list']
ARGV.shift
- After.find_pids(ARGV.shift)
+ $VERBOSE = true # so it'll output the names when searching...
+ query = ARGV.shift || ''
+ got = After.find_pids(query)
+ if got.empty?
+ puts "none found #{query}"
+ end
exit # premature exit
elsif ARGV[0] == '-p'
ARGV.shift
pid = ARGV.shift
+ puts "waiting for pid #{pid}" if $VERBOSE
After.wait_pid pid.to_i
else
After.find_and_wait_for(ARGV.shift)
end
- puts 'running', ARGV if $VERBOSE
+ puts 'done waiting, now running:', ARGV if $VERBOSE
system(*ARGV) if ARGV.length > 0
end
end