windows批处理循环没有完成

试图让这个batch file循环遍历一个列表( list.txt ),并使用xml.exe从这个文件中报告一个数字: http : xml.exe

文件:

 @echo off SET USER_NAME=registereduser SET PASSWORD=secret SET LIST=list.txt SETLOCAL EnableDelayedExpansion EnableExtensions net use * /del /yes > null FOR /F %%A in ('TYPE "%LIST%"') do ( NET USE * \\%%A\c$ /user:%USER_NAME% %PASSWORD% > null SET DATA=\\%%A\c$\directory here\file.xml ) SET A_NUM= FOR /F %%I IN ('bin\xml sel -t -v "//Editable[@name='MachineID.SerialNumber']/@default" "%DATA%"') DO (SET A_NUM=%%I) IF "%A_NUM%" == "" ( ECHO ******************************************************** ECHO *** ERROR : CAN'T CONNECT *** ECHO ******************************************************** GOTO END ) ELSE ( ECHO A NUMBER FOUND : %A_NUM% ECHO. ) 

结果:

 A NUMBER FOUND : 5300 

预期成绩:

 A NUMBER FOUND : 5300 A NUMBER FOUND : 4100 A NUMBER FOUND : 2600 

我看到它映射驱动器,但它不会在所有机器上运行脚本。

– -编辑 – –

这是嵌套循环?

 @echo off SET USER_NAME=registereduser SET PASSWORD=secret SET LIST=list.txt SETLOCAL EnableDelayedExpansion EnableExtensions net use * /del /yes > null FOR /F %%A in ('TYPE "%LIST%"') do ( NET USE * \\%%A\c$ /user:%USER_NAME% %PASSWORD% > null SET DATA=\\%%A\c$\directory here\file.xml SET A_NUM= FOR /F %%I IN ('bin\xml sel -t -v "//Editable[@name='MachineID.SerialNumber']/@default" "%DATA%"') DO (SET A_NUM=%%I) IF "%A_NUM%" == "" ( ECHO ******************************************************** ECHO *** ERROR : CAN'T CONNECT *** ECHO ******************************************************** GOTO END ) ELSE ( ECHO A NUMBER FOUND : %A_NUM% ECHO. ) ) 

错误:

 > .\anumber2.bat failed to load external entity "" ******************************************************** *** ERROR : CAN'T CONNECT *** ******************************************************** The system cannot find the batch label specified - END failed to load external entity "" ******************************************************** *** ERROR : CAN'T CONNECT *** ******************************************************** 

Solutions Collecting From Web of "windows批处理循环没有完成"

在Squashman的帮助下,我有一个答案!

 @echo off SET USER_NAME=registereduser SET PASSWORD=secret SET LIST=list.txt SETLOCAL EnableDelayedExpansion EnableExtensions net use * /del /yes > null FOR /F %%A in ('TYPE "%LIST%"') do ( NET USE * \\%%A\c$ /user:%USER_NAME% %PASSWORD% > nul SET DATA=\\%%A\c$\directory here\file.xml SET A_NUM= FOR /F %%I IN ('bin\xml sel -t -v "//Editable[@name='MachineID.SerialNumber']/@default" "!DATA!"') DO (SET A_NUM=%%I) IF "!A_NUM!" == "" ( ECHO ******************************************************** ECHO *** ERROR : CAN'T CONNECT *** ECHO ******************************************************** GOTO END ) ELSE ( ECHO A NUMBER FOUND : !A_NUM! ECHO. ) ) 

结果:

 > .\anumber2.bat A NUMBER FOUND : 4100 A NUMBER FOUND : 5300