(view source code of tee.bat as plain text)
@ECHO OFF
:: Check Windows versionIF NOT "%OS%"=="Windows_NT" GOTO Syntax
:: Keep variables localSETLOCAL
:: Check command line argumentsSET Append=0
IF /I [%1]==[-a] (
SET Append=1
SHIFT
)IF [%1]==[] GOTO Syntax
IF NOT [%2]==[] GOTO Syntax
:: Test for invalid wildcardsSET Counter=0
FOR /F %%A IN ('DIR /A /B %1 2^>NUL') DO CALL :Count "%%~fA"
IF %Counter% GTR 1 (
SET Counter=
GOTO Syntax
):: A valid filename seems to have been specifiedSET File=%1
:: Check if a directory with the specified name existsDIR /AD %File% >NUL 2>NUL
IF NOT ERRORLEVEL 1 (
SET File=
GOTO Syntax
):: Specify /Y switch for Windows 2000 / XP COPY commandSET Y=
VER | FIND "Windows NT" > NUL
IF ERRORLEVEL 1 SET Y=/Y
:: Flush existing file or create new one if -a wasn't specifiedIF %Append%==0 (COPY %Y% NUL %File% > NUL 2>&1)
:: Actual TEEFOR /F "tokens=1* delims=]" %%A IN ('FIND /N /V ""') DO (
> CON ECHO.%%B
>> %File% ECHO.%%B
):: DoneENDLOCAL
GOTO:EOF
:CountSET /A Counter += 1
SET File=%1
GOTO:EOF
:SyntaxECHO.
ECHO Tee.bat, Version 2.11a for Windows NT 4 / 2000 / XP
ECHO Display text on screen and redirect it to a file simultaneously
ECHO.
IF NOT "%OS%"=="Windows_NT" ECHO Usage: some_command ³ TEE.BAT [ -a ] filename
IF NOT "%OS%"=="Windows_NT" GOTO Skip
ECHO Usage: some_command ^| TEE.BAT [ -a ] filename
:SkipECHO.
ECHO Where: "some_command" is the command whose output should be redirected
ECHO "filename" is the file the output should be redirected to
ECHO -a appends the output of the command to the file,
ECHO rather than overwriting the file
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
ECHO Modified by Kees Couprie
ECHO http://kees.couprie.org
ECHO and Andrew Cameron
page last modified: 2025-10-11; loaded in 0.0050 seconds