如何从ssh输出中删除颜色等 [英] How to remove colors etc. from ssh output

查看:700
本文介绍了如何从ssh输出中删除颜色等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jsch从本地ssh服务器获取ssh输出。

i am using jsch to get ssh output from a local ssh server.

当我在文本框中显示输出时,得到所有这些奇怪的字符串在输出例如:

When i display the output in a textbox i get all these weird string in the output for example:

] 0;〜/ rails_sites / rex_raid

]0;~/rails_sites/rex_raid

[32mRob @ shinchanii [33m〜/ rails_sites / rex_raid [0m

[32mRob@shinchanii [33m~/rails_sites/rex_raid[0m

我想[33m和[0m标记一种新颜色或某物的开始和] 0;〜标记一个换行符

I guess [33m and [0m mark the begin of a new color or something and ]0;~ marks a newline

如何摆脱这些字符串解析这些字符串的输出?

how do i get rid of these withput parsing the output for those strings ?

这里是一个例子(不是从我) :

Here a example (not from me) how my output looks like:

http://www.google.de/codesearch#048v6jEeHAU/typescript&q=%5D0;~&l=1

推荐答案

这些实际上是VT100终端控制转义序列。您可以在 http://找到其列表(不确定列表是否完整)。 www.termsys.demon.co.uk/vtansi.htm

These are actually VT100 terminal control escape sequences. You can find a list of them (not sure if the list is complete) at http://www.termsys.demon.co.uk/vtansi.htm.

您可以使用String的replaceAll方法( http:/ /download.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#replaceAll%28java.lang.String,%20java.lang.String%29 ),然后创建正则表达式匹配所有有效的VT100转义序列。但是在创建正则表达式时,不要忘记在方括号前面有不可打印的ESC字符(即Unicode中的\\\)。

You can use the String's replaceAll method (http://download.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#replaceAll%28java.lang.String,%20java.lang.String%29), and create a regular expressions which matches all valid VT100 escape sequences. However when creating the regexp do not forget that there is non printable ESC char (that is \u001B in Unicode) before the square bracket.

这篇关于如何从ssh输出中删除颜色等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆