首页 文章

Windows批处理文件错误级别问题

提问于
浏览
0

我有一个批处理文件,它从文本文件中解析出一堆文件名,并将它们连接成一个强大的文件 - 之前已经讨论过here . 但是,我没有尝试过:

set FILE_LIST=
for /f %%x in (temp.txt) do (

:: perform a VCS test
accurev diff -b %%x

:: skip concatenation if error level is > 2
IF errorlevel 2 GOTO NEXT

:: perform the concatenation
set FILE_LIST=!FILE_LIST! %%x

:NEXT
:: print a message if here due to an error above
IF errorlevel 2 echo VCS problem with this file: %%x
)

问题是 - 一旦发现一个大于2的错误级别,脚本似乎停止执行整个for循环 . 如果列表中有五个文件而第三个文件有VCS问题 - 脚本只处理前两个 .

2 回答

  • 0
    setlocal ENABLEDELAYEDEXPANSION
    set FILE_LIST=
    for /f %%x in (temp.txt) do (
        accurev diff -b "%%~x"
        IF errorlevel 2 (
            echo VCS problem with this file: %%~x
        ) ELSE (
            set FILE_LIST=!FILE_LIST! %%x
        )
    )
    
  • 0

    如果ERRORLEVEL构造有一个奇怪的特性......如果返回码等于或高于指定的errorlevel,则返回TRUE .

    参考this link了解如何处理"feature" .

相关问题