Redirecting colored output + into logfile

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
pstein
Posts: 125
Joined: 09 Nov 2011 01:42

Redirecting colored output + into logfile

#1 Post by pstein » 16 Nov 2015 02:38

Some nice command line tools use (partially) colored output to emphasis certain lines.

Example: If one uses the well known video tool ffmpeg for validation in a command like:

Code: Select all

ffmpeg -loglevel warning -i D:\videos\soemcorruptedfile.mp4 -f null - 


then the ffmpeg warnings are displayed in colors at the commandprompt.
Excellent so far.

Now I want to redirect the ffmpeg output to a logfile and want to keep the colored lines.

So when I code

ffmpeg ..... >D:\myoutput.log 2>D:\myoutput.log

or

ffmpeg ..... >D:\myoutput.log 2>&1

And open the resulting logfile in a well know editor like Notepad++ then there is no color any more.
Just black-on-white text.

How can I redirect the colors as well?

Are colors a matter of ANSI or Unicode?

Is the issue of not-color-displaying possibly only a Notepad++ problem?

Even worse: If I do not redirect output to logfile but just the warnings from stderr to stdout then the colors are vanishing:

ffmpeg ..... 2>&1

miskox
Posts: 553
Joined: 28 Jun 2010 03:46

Re: Redirecting colored output + into logfile

#2 Post by miskox » 16 Nov 2015 02:59

Probably we would need a dump of this logfile - to see if it contains ESCAPE characters.

Print screen too (if possible).

Saso

einstein1969
Expert
Posts: 941
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: Redirecting colored output + into logfile

#3 Post by einstein1969 » 16 Nov 2015 06:04

I think that the program output in two different method.

When write to file not insert color. When write to console then write the color.

But this is my suppose.

Can we capture the color on the screen?

On 32Bit platform is possible via DEBUG.EXE.

EDIT:

Code: Select all

By default the program logs to stderr, if coloring is supported by the terminal, colors are used to mark errors and warnings. Log coloring can be disabled setting the environment variable AV_LOG_FORCE_NOCOLOR or NO_COLOR, or can be forced setting the environment variable AV_LOG_FORCE_COLOR. The use of the environment variable NO_COLOR is deprecated and will be dropped in a following FFmpeg version. 

source

einstein1969

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Redirecting colored output + into logfile

#4 Post by penpen » 16 Nov 2015 08:16

einstein1969 wrote:Can we capture the color on the screen?
One could use powershell:
http://blogs.msdn.com/b/powershell/archive/2009/01/11/colorized-capture-of-console-screen-in-html-and-rtf.aspx.

penpen

Post Reply