Verwenden eines benutzerdefinierten Tee-Befehls für die BAT-Datei

Ich versuche das zu benutzentee Code für eine Fledermausdatei geschrieben, aber ich habe Probleme, ihn in meinem Code zu implementieren. Ich möchte keine Installationen von Drittanbietern verwenden, um das Tee-Problem zu lösen, da der Code funktionieren soll, wenn ich meinen Computer in einem Jahr formatiere und das Programm erneut ausführen möchte.

Ich habe es so eingerichtet:

mycommand.exe | tee.bat -a output.txt

Ich habe es mit einem separaten versucht.bat Datei und versucht, als eine Funktion (bevorzugt) in das Original aufzunehmen.bat ohne Erfolg mit:

myprogram.exe | call tee -a output.txt
echo.
echo.
echo.
SET /P restart="Do you want to run again? (1=yes, 2=no): "
if "%restart%"=="1" GOTO LoopStart


::--------------------------------------------------------
::-- Function section starts below here
::--------------------------------------------------------
:tee
:: Check Windows version
IF NOT "%OS%"=="Windows_NT" GOTO Syntax
| 
:: Keep variables local
SETLOCAL

:: Check command line arguments
SET Append=0
IF /I [%1]==[-a] (
    SET Append=1
    SHIFT
)
IF     [%1]==[] GOTO Syntax
IF NOT [%2]==[] GOTO Syntax

:: Test for invalid wildcards
SET 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 specified
SET File=%1

:: Check if a directory with the specified name exists
DIR /AD %File% >NUL 2>NUL
IF NOT ERRORLEVEL 1 (
    SET File=
    GOTO Syntax
)

:: Specify /Y switch for Windows 2000 / XP COPY command
SET Y=
VER | FIND "Windows NT" > NUL
IF ERRORLEVEL 1 SET Y=/Y

:: Flush existing file or create new one if -a wasn't specified
IF %Append%==0 (COPY %Y% NUL %File% > NUL 2>&1)

:: Actual TEE
FOR /F "tokens=1* delims=]" %%A IN ('FIND /N /V ""') DO (
    >  CON    ECHO.%%B
    >> %File% ECHO.%%B
)

:: Done
ENDLOCAL
GOTO:EOF


:Count
SET /A Counter += 1
SET File=%1
GOTO:EOF


:Syntax
ECHO.
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
:Skip
ECHO.
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

Ich versuche, die Ausgabe zu teilen, damit ich die Konsolenausgabe in einer Datei speichern und trotzdem mit dem laufenden Programm interagieren kann.

Wie kann ich erreichen, dass der Tee-Befehl ordnungsgemäß mit meiner .bat-Datei zusammenarbeitet, damit ich die Ausgabe sowohl in eine Datei als auch in die Konsole aufteilen kann?

Antworten auf die Frage(1)

Ihre Antwort auf die Frage