我需要在ssh屏幕中显示格式化输出

时间:2012-01-13 11:50:45

标签: ruby-on-rails ruby shell command-line ruby-on-rails-3.1

在Ruby或Rails中: - 我需要显示在命令提示符下显示的下面编码的输出。

require 'net/ssh'

Net::SSH.start( hostname, username, :password => password ) do|ssh|

result = ssh.exec!('ls -ltr')

puts result

end

让我知道怎么可能?

Command(ls -ltr)是动态的 目前的输出是:

total 257140 drwxrwxr-x 8 folderabc folderabc 4096 Set 4 2010 sources drwxrwxr-x 13 folderabc folderabc 4096 Set 4 2010 teste -rwxrwxr-x 1 folderabc folderabc 72 Set 7 2010 clean_memory -rw-rw-r-- 1 folderabc folderabc 263012352 Mar 17 2011 ngforms_production.sql -rw-rw-r-- 1 folderabc folderabc 21 Jun 23 2011 phps.php drwxrwxr-x 15 folderabc folderabc 4096 Jun 30 2011 ngforms -rw-rw-r-- 1 folderabc folderabc 751 Jul 1 2011 ngforms_word.sql -rw-rw-r-- 1 folderabc folderabc 31 Jul 5 2011 test.php drwxrwxr-x 5 folderabc folderabc 4096 Nov 4 10:52 dump drwxrwxrwx 2 folderabc folderabc 4096 Jan 13 00:00 mysqlbackup

1 个答案:

答案 0 :(得分:2)

尝试使用<pre>标记。还要确保您使用的字体是等宽字体之一,如CourierNew

<pre><%= result %></pre>