How do I color output text from Perl script on Windows?

后端 未结 5 951
别那么骄傲
别那么骄傲 2021-02-06 00:36

I would like to color format the text printed to the console using the Perl print command.

In my case the script will only be run under WinXP-DOS Command Line but it wou

5条回答
  •  孤独总比滥情好
    2021-02-06 01:01

    Here is what worked best for me after all:

    1) Installed Win32::Console::ANSI (note that this is not the same as Win32::Console)

    perl -MCPAN -e shell
    cpan> install Win32::Console::ANSI
    

    2) If this module is loaded before Term::ANSIColor, you can use the standard Term::ANSIColor API and it actually works (I tried it with Windows 7).

    use Win32::Console::ANSI;
    use Term::ANSIColor;
    
    print color("blue"), "blue\n", color("reset");
    print "normal\n";
    

提交回复
热议问题