Reputation: 19
I'm trying to use for loop and read contents of a file line by line
the file is an xml
and contains urls and paths delimited by <>
I am using the following code
set @LOGFILE=F:\nircmd\hosts.xml
:loop
for /F "tokens=2-3 delims=<>" %%a in (%LOGFILE%)do echo "it works"
timeout /t
goto :loop
the batch is terminating as soon as it encounters the for loop
i have already tried to pause or timeout the batch but nothing seems to work batch is anyway terminating
what to do?
Upvotes: 1
Views: 50
Reputation: 354446
That is because there is no variable LOGFILE
; you named your variable @LOGFILE
. Thus the for
loop encounters an error because it cannot find the file to read and errors such as these terminate the batch file. So either use
for /F "tokens=2-3 delims=<>" %%a in (%@LOGFILE%)
or
set LOGFILE=F:\nircmd\hosts.xml
Upvotes: 1