At first, it is relatively easy to write a TEE.BAT program. The only problem is that set /p command (used to get the output from the command) doesn't differentiate between the end of file and an empty line. This mean that the output will be captured until the first empty line (or the end of file):
@echo off
:: usage: AnyCommand | TEE filename
setlocal EnableDelayedExpansion
if exist %1 del %1
:nextLine
set line=:EOF
set /p line=
if "!line!" == ":EOF" goto :eof
echo(!line!
echo(!line!>> %1
goto nextLine
You may test that this Batch file indeed works this way:
tee CopyOfFile.txt < File.txt
However, when this Batch file is used in the way it was designed, it fails now and then:
type File.txt | tee CopyOfFile.txt
Previous line sometimes works ok and sometimes show and store just the first line of the file. I made several tests and can not isolate the cause of the error. Perhaps someone (jeb?) could explain what is happening in this case and give a solution.