English 中文(简体)
读取 Java 外部进程时的混固文本
原标题:Garbled text while reading from external process in Java

我正在启动与Cygwin捆绑的 SSH 工具, 使用 Java 的 ProcessBuilder 类。 一切正常。 我连接到 SSH 上的 linux 服务器, 可以运行命令并读取输出 。

然而,每当返回输出时, 只有在登录到服务器和运行命令( 如目录列表 < code> > ls ) 之后, 才会返回这样的输出 :

InputStream: root@myserver:/scripts/common# ls 
InputStream: [00m[00mA1-4.yaml[00m                            [01;32mscip-1.2.0.linux.x86_64.gnu.opt.qso[00m
InputStream: [00madditional_files.txt[00m                 [01;32mscip-1.2.0.linux.x86_64.gnu.opt.spx[00m

据我所知,它只发生在文件列表命令中。例如,当我运行像时间这样的其它命令时, 它会显示正常输出 。

你能建议在文件名中附加这些随机字符的是什么吗?

我甚至试图使用 UTF8 编码,但是没有变化。 当我使用命令行直接登录时, 我看不到这些结果。 但是, cmdline 显示的是彩色值中的文件名称。 是否添加了一些不是 ASCII 的额外信息?

最佳回答

使用命令 ls -- color=none 解决了这个问题。

之所以发生这种情况,是因为默认情况下命令返回带有不同颜色代码值的文件名。 此链接提供更多信息

以下图片描述 >ls >ls -- color=none 之间的区别:

""https://i.sstatic.net/kR7Bm.png" alt="此处输入图像描述"/ >

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签