Topic: `ps -el` system command view problem

I am trying to show all processes running on my server and output that to one of my views.
What I have here works but somehow I need to add a "\n" or a line break to the result.
This is what I have in my controller:

def processes
x=`ps -el`
y=x.split("\n")
y.each do |line|
end
return y
end

Then I display the variable in my view with: <%= processes() %>

Here is what the view looks like:

F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD000 S 2202 11254 1 0 75 0 - 545 wait4 ? 00:00:00 mysqld_sa000 S 2202 11342 11254 0 80 5 - 5887 schedu ? 00:00:00 mysqld040 S 2202 11368 11342 0 80 5 - 5887 schedu ? 00:00:01 mysqld040 S 2202 11370 11368 0 80 5 - 5887 rt_sig ? 00:00:00 mysqld000 S 2202 22812 1 0 75 0 - 5744 schedu ? 00:00:00 dispatch.000 S 2202 23955 1 0 75 0 - 5322 schedu ? 00:00:00 dispatch.100 S 2202 23807 23691 0 75 0 - 579 schedu pts/4 00:00:00 sh000 T 2202 26309 23807 0 75 0 - 1137 do_sig pts/4 00:00:00 irb040 S 2202 18127 1 2 75 0 - 6578 schedu ? 00:00:00 httpd040 S 2202 18132 18127 0 75 0 - 6299 schedu ? 00:00:00 httpd040 S 2202 18172 18127 0 75 0 - 6605 schedu ? 00:00:00 httpd000 S 2202 18178 18132 17 79 0 - 5475 pipe_w ? 00:00:00 dispatch.040 S 2202 18185 18127 0 76 0 - 6581 schedu ? 00:00:00 httpd000 R 2202 18218 18178 0 80 0 - 397 - ? 00:00:00 ps100 S 2202 18219 1475 0 77 0 - 503 wait4 ? 00:00:00 sps000 R 2202 18235 18219 0 78 0 - 897 - ? 00:00:00 ps

I would like to display each line in it's correct position in the table so the output makes sense. Would anyone know how I can get this command's output to display properly?

Thanks again,

jackster

Re: `ps -el` system command view problem

The problem you have is an HTML one, not a ruby one.

Basically, HTML ignores a \n unless it is inside a <pre> </pre> tag.

So, you can do this instead:

<pre>
  <%= processes %>
</pre>

And it should work fine.

Also your Ruby code can be just:

def processes
  `ps -el`
end

To get the same result.  You don't need all that splitting or assignments or even return command.

Regards

Mikel

Re: `ps -el` system command view problem

Mikel,
man...you sure saved me a lot of work!
thanks...it works perfectly.
Now I'm going to try and pass some params to this and some other system calls to be able to view them from the web server....
again, thank alot

jackster