问题
I am new to writing batch files. I am trying to do the following .
Read line by line from file called list.txt which has two tokens which are space seperated and in the next for loop i am tokenizing and sending these tokens as parameters to another script.
FOR /F %%i IN (C:\list.txt) DO
FOR /F "tokens=1,2 delims= " %%A IN (%%i) DO
winscp.com /script=C:\myscript1.txt /parameter %%A C:\%%B
But I am getting the following error. Do was un expected at this time.
Can some one explain what am I missing.
Thanks
回答1:
Independently of the already solved problem, you may achieve the token separation in the same FOR that read the file. Also, FOR command have spaces as default separators, so delims= "
is not needed. That is:
FOR /F "tokens=1,2" %%A IN (C:\list.txt) DO (
winscp.com /script=C:\myscript1.txt /parameter %%A C:\%%B
)
回答2:
Batch files aren't free form and plenty of whitespace is significant. Such as in this case where you could write it all in one line but you cannot spread it out over several lines.
Another option is to explicitly use blocks:
FOR /F %%i IN (C:\list.txt) DO (
FOR /F "tokens=1,2 delims= " %%A IN (%%i) DO (
winscp.com /script=C:\myscript1.txt /parameter %%A C:\%%B
)
)
来源:https://stackoverflow.com/questions/9949579/nested-for-loop-in-batch-file-error-do-was-unexpected-at-this-time