Question

That is display both streams on console but distinguish somehow one from another.

Normally is that I don't know which lines are stderr they are mixed with normal output. If I redirect it to a file then I don't know when in relation to normal output the error happened. So is there a way so every line that comes from stderr would have some indicator like for example a string at the beginning like this:

c:\>command.exe

normal output
normal output
normal output
stderr: error message
normal output
stderr: error message
normal output

This is especially problem in compilers/make which spew lot of information and mix those two streams. I know I can prepend every line of text with given string using unix sed but I do not know how to use it with relation to main program. If I join two streams string will be prepended to every line. If I redirect stderr to file it won't be displayed on console + it will get out of context from stdout.

Était-ce utile?

La solution

If the purpose is to distinguish error messages from normal output in the same screen, then it may be done via this trick:

anycompiler params ... 2>&1 1>&3 | findstr /N /A:4E "^"

This way the error messages appears preceded by a line number in yellow color on red background.

Previous answer extracted from: Batch - How can I redirect stderr and stdout from within the batch script itself?

If you redirect both outputs of previous line to a disk file, STDERR output will be preceded by a line number.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top