Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Garbled text while reading from external process in Java

I am launching the SSH utility bundled with Cygwin, using ProcessBuilder Class in Java. Everything works fine. I connect to a linux server over SSH, can run commands and read the output.

However, whenever the output is returned, it only happens after login on the server and running commands e.g directory listing 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 far as I have figured out, it is only happening with file listing command. For example when I am running other commands like time, etc it shows normal output.

Can you suggest what it is that is appending these random characters to the filename?

I have even tried to use UTF8 encoding but nothing changes. When I directly login using the command line, I do not see those results. However, the cmdline shows file names in colored values. Is it that there is some additional information added which is not ASCII?

like image 544
Johnydep Avatar asked Apr 28 '26 00:04

Johnydep


1 Answers

Using the command ls --color=none solves this problem.

This happens because by default ls command returns file names which have different color code values appended to them. This link gives more information.

Following picture describes the difference between ls and ls --color=none:

enter image description here

like image 140
Johnydep Avatar answered Apr 30 '26 13:04

Johnydep



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!