Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Restore normal text color in windows console

by ambrus (Abbot)
on May 31, 2013 at 11:02 UTC ( #1036226=CUFP: print w/replies, xml ) Need Help??

I run ffmpeg from a windows console. It colors its messages, eg. warnings are (red) yellow and errors are bright red. That's all good, but when I interrupt ffmpeg, it sometimes leaves the console color changed and then all further text in the same console will be written in that color.

The cls command does not restore the color like it used to in some windows versions. Rerunning ffmpeg doesn't help because it checks the console color when it starts and restores that when it exits. I don't wish to close the console and start a new one because that would lose the command history. Thus, I need a separate command to reset the console colors. Here's a simple command to do that (put it into a batch file). Works with ActiveState perl 5.16.1.

perl -we "use Win32::Console; $con = Win32::Console->new(STD_OUTPUT_HA +NDLE()); $con->Attr($FG_CYAN);"

Replies are listed 'Best First'.
Re: Restore normal text color in windows console
by BrowserUk (Pope) on May 31, 2013 at 11:17 UTC

    You should take a look at the color command:

    C:\test>color /? Sets the default console foreground and background colors. COLOR [attr] attr Specifies color attribute of console output Color attributes are specified by TWO hex digits -- the first corresponds to the background; the second the foreground. Each digit can be any of the following values: 0 = Black 8 = Gray 1 = Blue 9 = Light Blue 2 = Green A = Light Green 3 = Aqua B = Light Aqua 4 = Red C = Light Red 5 = Purple D = Light Purple 6 = Yellow E = Light Yellow 7 = White F = Bright White If no argument is given, this command restores the color to what it wa +s when CMD.EXE started. This value either comes from the current consol +e window, the /T command line switch or from the DefaultColor registry value. The COLOR command sets ERRORLEVEL to 1 if an attempt is made to execut +e the COLOR command with a foreground and background color that are the same. Example: "COLOR fc" produces light red on bright white

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      Thanks! This command also works. It has the side effect of changing the color of existing text in the console, but I can live with that.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://1036226]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2017-03-30 12:00 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (356 votes). Check out past polls.