Perl color specifiers with redirected output

I have a Perl script that uses Term::ANSIColor. It used to be that if I redirect the output to a file > file.txt, then the file contains only text, not color codes^[[0m

Something has changed on my machine, Ubuntu 10.04, so the redirected output includes these special characters that define the color.

Any idea how to fix this? Can I detect redirection of output from inside a perl script and skip the color part?

Thank!

+5
source share
1 answer

You can check if you are working interactively using IO :: Interactive :

use IO::Interactive qw(is_interactive);

if (is_interactive())
{
    # show some fancy color
}

IO:: Interactive ( , STDIN tty -t), Conway.

+6

All Articles