4

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.

rsk82
  • 28,217
  • 50
  • 150
  • 240

1 Answers1

2

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.

Community
  • 1
  • 1
Aacini
  • 65,180
  • 12
  • 72
  • 108
  • does this wait until the first process (`anycompiler params ...`) exits? Is there a way to make the data is flow continously into the pipe, the two process running at the same time? For example [new]line-buffered, or at some buffer rate (ie. buffer=4096)? – n611x007 Jun 05 '13 at 10:12