开发者

Batch redirection to two locations

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 开发者_JAVA百科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?


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"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜