In my post on Redirecting Output to a File in Windows Batch Scripts, I discussed the basics of output redirection into a text file and how this can be used for logging, including error logging by using the >& operator to combine the stderr and stdout streams. But Mark asked, “How do you just pipe stderr without joining it to stdout?” Good question!
So normal output redirection is handled with just the > or >> operators (depending on whether you want to overwrite or append the target file), like so:
dir >> myfile.txt
The operator outputs the stdout stream by default. But it can be modified to output the stderr stream by just specifying that stream with the operator. Remember, stderr is stream 2. So, you would do like so:
dir 2>> myfile.txt
This would write only the error output to the file.