Reputation: 10939
I've been having some troubles redirecting a batch file to a log file as well as having it display in the command console.
Is this even possible with windows batch, or do I have to resort to a simple program which intercepts stdout and writes the stream to a file and to stdout?
Upvotes: 2
Views: 194
Reputation: 101764
I don't think you can do this (properly) with just the built-in tools, you probably need to use a tee utility like the Win32 GNU ports (this or this) or mtee
Edit: You can of course use the FOR batch command, but the output is not live, you have to wait for the command to finish:
@echo off
setlocal ENABLEEXTENSIONS
goto main
:TEE
FOR /F "tokens=*" %%A IN ('%~2') DO (
>>"%~1" echo.%%A
echo.%%A
)
goto :EOF
:main
call :TEE "%temp%\log.txt" "ping -n 2 localhost"
Upvotes: 3