nested For loop in batch file error: Do was unexpected at this time

為{幸葍}努か 提交于 2020-02-02 16:07:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!