Advertisement
Wasif_Hasan_

TEE.bat

Sep 18th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.11 KB | None | 0 0
  1. @ECHO OFF
  2. SETLOCAL
  3.  SET Append=false
  4. IF /I "%~1]=="/a" ( SET Append=true & SHIFT )
  5. IF "%~1"== "" GOTO help
  6. IF "%~2"== "" GOTO help
  7.  SET Counter=0
  8. FOR /F %%A IN ('DIR /A /B %1 2^>NUL') DO CALL :Count "%%~fA"
  9.  IF %Counter% GTR 1 ( SET Counter= & GOTO Syntax )
  10.  SET File=%1
  11.  DIR /AD %File% >NUL 2>NUL
  12.  IF NOT ERRORLEVEL 1 ( SET File= & GOTO Syntax )
  13.  SET Y=
  14. VER | FIND "Windows NT" > NUL
  15. IF ERRORLEVEL 1 SET Y=/Y
  16.  IF %Append%==false  (COPY %Y% NUL %File% > NUL 2>&1)
  17.  FOR /F "tokens=1* delims=]" %%A IN ('FIND /N /V ""') DO (
  18.     > CON ECHO.%%B  
  19.         >> %File% ECHO.%%B
  20.  )
  21. ENDLOCAL
  22. GOTO:EOF
  23.  :Count
  24. SET /A Counter += 1
  25.  SET File=%1
  26. GOTO:EOF
  27.  :help
  28.  ECHO.
  29.  ECHO Display text on screen and redirect it to a file simultaneously ECHO Usage: some_command ^| TEE.BAT [ /a ] filename
  30.  ECHO.
  31. ECHO Where: "some_command" is the command whose output should be redirected
  32.  ECHO "filename" is the file the output should be redirected to
  33.  ECHO /a appends the output of the command to the file,
  34.  ECHO rather than overwriting the file
  35.  ECHO.
  36. ECHO Made by Wasif Hasan. Nov 2019
  37. Usage: command | tee
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement