Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 循环的批处理文件不工作_Windows_Batch File_Cmd - Fatal编程技术网

Windows 循环的批处理文件不工作

Windows 循环的批处理文件不工作,windows,batch-file,cmd,Windows,Batch File,Cmd,我试图在下面的循环中进行迭代,当执行if error accurrence时,循环应该转到if条件并退出,但循环永远不会转到if条件总是ELSE条件被执行,检查%errorlevel%是否有问题 SET list=clean all cfg1 CD "C:\SW\CONS\build" FOR %%a IN (%list%) DO ( CALL build.bat %%a IF %errorlevel% neq 0 ( echo Exiting the lo

我试图在下面的循环中进行迭代,当执行if error accurrence时,循环应该转到if条件并退出,但循环永远不会转到if条件总是ELSE条件被执行,检查%errorlevel%是否有问题

SET list=clean all cfg1 

CD "C:\SW\CONS\build"

FOR %%a IN (%list%) DO (
    CALL build.bat %%a
    IF %errorlevel% neq 0 (
        echo Exiting the loop
        EXIT /B %errorlevel%
    ) ELSE  (
        echo Successfully executed "%%a"......
    )
)
括号
中的变量只展开一次,因此当分析
for
循环时,
%ERRORLEVEL%
将替换为它所具有的任何值。您必须启用延迟扩展并使用
!错误等级,如果错误级别为
,则只需使用

for %%a in (%LIST%) do (
  call Build.bat %%a
  if errorlevel 1 (
    echo Exiting the loop
    goto :eof
  ) else (
    echo Successfully executed "%%a" . . .
  )
)

您需要使用延迟扩展和
!错误等级此解决方案对我有效,谢谢