2

When I do an "ls -l" on my linux box over PuTTY, it gives a clean, nicely colored output.

But when I try the same programmatically over plink, I land up getting all sort of control sequences, likely signifying those color values.

Can I somehow set the terminal options so that it doesn't send out these extra sequences for the colors, and just emits plain text?

[00mtotal 8956
drwxr-xr-x 8 pradymn users    4096 2010-07-23 12:29 [01;34mtestsb1[00m
drwxr-xr-x 5 pradymn users    4096 2010-07-24 22:49 [01;34mtest1[00m
-rw-r--r-- 1 pradymn users 9143013 2010-07-24 23:03 [00;31mtest1.tar.gz[00m

5 Answers 5

1

This is probably related to how you setup your ls to display colors. If you can post that we might be more helpful.

I recommend using the following in your favorite shell profile file (.bashrc): alias ls="ls --color=auto"

Alternatively when you don't want color output you can call ls using --color=never

0
5

Another alternative is to use the ansicon utility that sits between the console and plink and translates ANSI color codes on the fly:

$ ansicon.exe plink.exe user@host
1

To add to Rob's answer:

The ANSI escape sequences have to be interpreted by a terminal emulator program (or by a real hardware terminal). PuTTY is both a terminal emulator and a SSH client in one program.

But plink is just a SSH client designed to transfer raw binary data; it does not interpret ANSI sequences, just passes them to the terminal it is running in. On Windows, the terminal is the Windows console — and it does not support ANSI either.

If you want to use SSH from command line, try the Cygwin version of OpenSSH. PuTTY can be launched from command line too.

1

You could remove ANSI escape sequences with the following java regex (for exemple):

\\[..;..[m]|\\[.{0,2}[m]|\\(Page \\d+\\)|\u001B\\[[K]|\u001B|\u000F
0

For me following filtering works:

some-program | perl -pe 's/\e\[[0-9;]*[a-zA-Z]//g'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .