Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby - System Command - ps aux

Tags:

linux

ruby

So I'm trying to find the PID of any process which 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 that in ruby, all the distinct lines that would come back when run in linux, get concatenated into one long string. How can I have ruby read the results in as a list, instead of one long string?

like image 395
appleLover Avatar asked Oct 20 '22 11:10

appleLover


1 Answers

You can split it on the newline characters like so:

lines = (`ps aux | grep control`).split(/\n/)

With that done you can iterate over them, select things out using a regex, etc..

like image 97
David Hoelzer Avatar answered Oct 22 '22 00:10

David Hoelzer