TL;DR;
In CMD batch file on win - How to append / print a full loop output to both file AND screen simultaneously && continuously ?
Long Version :
I know that this is more of a powershell / bash task, or generally better suited for *nix / piping, but for some reason I need to do that on win (7!) batch / cmd.
I have a somewhat hacked super simple small primitive loop ( on win 7 ) with some network tasks to check (local) DNS listings updates every x seconds, flush local DNS and then check again for propagation. from win, to later be parsed by another script.
@echo off
set "domain=mydomain.TLD"
set "dns_host=dnshost.TLD"
set "NS1=ns1.dnshost.TLD"
set "NS2=ns1.dnshost.TLD"
set "neutralDNS=8.8.8.8"
set "timeout=60"
set "outputfile=myfile.txt"
FOR /L %%A IN (1,1,200) DO (
ECHO ************************************************  
ECHO ********* Checking %domain% On %NS1% //  %NS2%
ECHO ************* Loop Count :: %%A  %Time% 
ipconfig /flushdns
timeout  %timeout% 
ping %domain%
ping %dns_host%
ping %NS1%
ping %NS2%
nslookup %domain% %neutralDNS%
nslookup %dns_host% %NS1% 
nslookup ns1.%dns_host%
REM ... Loop goes on here, commands are not really important
REM host %dns_host%// we are not on *nix !
REM dig  %dns_host% @%neutralDNS% // we are not on *nix !
)
I would like to append the output of the loop to both file and screen, but when I try to append the output with >> myfile.txt like so :
 FOR /L %%A IN (1,1,200) DO (
    ECHO ************* Loop Count :: %%A  %Time% 
   ......
    ) >> %outputfile%
The execution simply fails, and when I try to output to file with > myfile like so :
 FOR /L %%A IN (1,1,200) DO (
    ECHO ************* Loop Count :: %%A  %Time% 
   ......
    ) > %outputfile%
The file will overwrite itself with every iteration.
Another issue is that there is no screen output on both cases except for explicit echo.
 
    