so, if you're using a hash like I think you might be:
s = <output of ps command>
h = {}
s.each_line do |line|
_, pid, _, cmd = *(line.match /(\d+)\s.*(:\d+){2}\s(.*?)$/)
h[pid] = cmd
end
I think that should work.
Todd
_, pid
···
On 7/10/07, Divya Badrinath <dbadrinath@dash.net> wrote:
Robert Dober wrote:
> On 7/10/07, James Edward Gray II <james@grayproductions.net> wrote:
>> sec, last = cols.values_at(1, -1)
> Very interesting James, I seem to be rather extreme and
>
> sec, last = string.split.values_at(1, -1)
> might be a tad to long for one line in your style, however Ruby syntax
> just supports this marvelous syntax
>
> sec, last = string.split.
> values_at(1, -1)
>
> Robert
cmd = string[/\s(\S+)$/, 1]
doesnt fetch me anything:)
program=string.split.last
what if
string = "root 14051 14033 3 08:39 pts/2 00:00:00 /bin/bash -x
-s"
it fetches only -s for me.
sec, last = string.split.values_at(1, -1)
doesnt work for the same reason
i need everything after 00.00.00 till the end
i.e., /bin/bash -x -s
program=string[/[a-z\/]+$/]
the command column mauy start with character. i dont want to limit it in
my regexp. it has to be generic.
with all your comments, i tried
pid = run_process[/\s(\d+)/, 1]
cmd = run_process[/:\d+:\d+\s(\S.*)\s$/, 1]
On Behalf Of Divya Badrinath:
# string = "root 14051 14033 3 08:39 pts/2 00:00:00 /bin/bash -x -s"
# it fetches only -s for me.
# sec, last = string.split.values_at(1, -1)
# doesnt work for the same reason
# i need everything after 00.00.00 till the end
# i.e., /bin/bash -x -s
you can modify the non-regex solutions since they are just plain array manipulations
cmd = string[/\s(\S+)$/, 1]
doesnt fetch me anything:)
No idea that was not my code
program=string.split.last
what if
string = "root 14051 14033 3 08:39 pts/2 00:00:00 /bin/bash -x
-s"
it fetches only -s for me.
As simple as possible, but not simpler. Now we are in the simpler case
But see below
program=string[/[a-z\/]+$/]
the command column mauy start with character. i dont want to limit it in
my regexp. it has to be generic.
with all your comments, i tried
pid = run_process[/\s(\d+)/, 1]
cmd = run_process[/:\d+:\d+\s(\S.*)\s$/, 1]
Does not work the :\d+ stuff might be a parameter of the program
is there any other way?
Yep counting fields after all
x = split
y= x[1]
z = x[7..-1].join(" ")
There might still be a pitfall though in case of some old processes
where you will have to analyse if the date takes one or two fields if
memory serves.
HTH
Robert
···
On 7/10/07, Divya Badrinath <dbadrinath@dash.net> wrote:
--
I always knew that one day Smalltalk would replace Java.
I just didn't know it would be called Ruby
-- Kent Beck
> Very interesting James, I seem to be rather extreme and
>
> sec, last = string.split.values_at(1, -1)
> might be a tad to long for one line in your style, however Ruby syntax
> just supports this marvelous syntax
>
> sec, last = string.split.
> values_at(1, -1)
What is your terminal width, 30?
oops wrong thread, I was caught in the "Beautiful Code Thread".
Sorry
Robert
···
On 7/10/07, Gregory Brown <gregory.t.brown@gmail.com> wrote:
On 7/10/07, Robert Dober <robert.dober@gmail.com> wrote:
> On 7/10/07, James Edward Gray II <james@grayproductions.net> wrote:
> > On Jul 10, 2007, at 3:25 PM, Divya Badrinath wrote:
--
I always knew that one day Smalltalk would replace Java.
I just didn't know it would be called Ruby
-- Kent Beck
# On Behalf Of Divya Badrinath:
# # string = "root 14051 14033 3 08:39 pts/2 00:00:00
# /bin/bash -x -s"
# # it fetches only -s for me.
# # sec, last = string.split.values_at(1, -1)
# # doesnt work for the same reason
# # i need everything after 00.00.00 till the end
# # i.e., /bin/bash -x -s