Harmonic text when reading from an external process in Java

I am running the SSH utility bundled with Cygwin using the ProcessBuilder class in Java. Everything is working fine. I connect to a Linux server via SSH, I can run commands and read the output.

However, whenever the output is returned, this only happens after entering the server and running commands, for example, a list of directories ls, returns something like this:

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

As I understand it, this only happens with the file list command. For example, when I run other commands, such as time, etc., It shows a normal output.

Can you suggest what adding these random characters to the file name is?

I even tried using UTF8 encoding, but nothing changed. When I log in directly using the command line, I do not see these results. However, cmdline shows file names in color values. Is there any additional information that is not ASCII?

+3
source share
1 answer

Using the command ls --color=nonesolves this problem.

This is because, by default, the ls command returns the names of files that add different color code values ​​to them. This link provides more information .

The following image describes the difference between lsand ls --color=none:

enter image description here

+1
source

All Articles