简体   繁体   中英

Issues with windows batch file loop

I have the code to loop through a file with a list of servers followed by executing the nslookup command.

Code

setlocal EnableDelayedExpansion
set file=servers.txt
FOR /F %%i IN (%file%) DO (
set server=%%i
nslookup !server!
)

Issues

  1. Even if there is a single line, it loops forever
  2. The nslookup command returns no value

Since your batch file is called nslookup - the line nslookup !server! is calling the batch script itself with the argument !server! (of course this argument is not being used), instead of the actual nslookup command.

To fix the issue, you need to rename the batch file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM