output both stderr and stdout to file, and only stderr to command prompt

When my batch script runs, I want any errors to show up on the command prompt, so the user sees it straight away, while suppressing all the standard output that shows up.

But I want everything to be outputted to a log file. How do I do this?

In other words,

+---------+
|         | --- stderr ---------> Console
| Program |
|         | --- stdout/err -----> Log file
+---------+

Solution 1:

There are various versions of tee that can be downloaded (or created using VBS or JScript), and you could redirect stderr to stdout and pipe everything through tee. But then you would get both stdout and stderr to both the console and the file.

I believe it is impossible to send both to a file, yet selectively send stderr to the console, unless there is something special in the content of all errors that could be used to identify an error. I doubt there is a consistent unique identifier for errors, but if there is, the solution could look something like this:

yourScript 2>&1 | tee output.log | find "Error:" 

Solution 2:

If you don't have tee:

yourScript 2>&1 > output.log & type output.log | find "Error:"