Ruby - System Command - ps aux
So, I'm trying to find the PID of any process that has the word "control" in it. I'm in ruby on Linux. This is the basic code so far
`ps aux | grep control`
If I run this in ruby, all the crisp lines that come back when run on linux are concatenated into one long line. How can I read ruby results as a list rather than one long line?
+3
appleLover
source
to share
2 answers
You can break it down to newlines like so:
lines = (`ps aux | grep control`).split(/\n/)
With this, you can iterate over them, select things with a regex, etc.
+2
David Hoelzer
source
to share
Since you are on Linux, you can check the / proc filesystem. There are / proc // directories, and / proc // cmdline has a command line.
0
Chuckcottrill
source
to share