Windows批处理文件ERRORLEVEL问题 [英] Windows batch-file errorlevel question
问题描述
我已经得到了解析一堆文件名出一个文本文件,并将它们连接成一个强大的批处理文件 - 这是previously讨论的此处。不过,我不希望字符串包含一个文件,如果当我通过一些命令来运行它(如VCS检查,例如)文件抛出一个错误。这里是我的尝试:
集file_list中=
FOR / F %%倍In(TEMP.TXT)做(::执行VCS测试
AccuRev的差异-b %%点¯x::跳级联,如果误差水平> 2
IF ERRORLEVEL 2 GOTO NEXT::执行级联
设置file_list中=!file_list中! %%X:下一个
::打印一条消息,如果这里因错误而上述
IF错误级别2回波VCS问题这个文件:%%点¯x
)
问题是 - 脚本似乎停止尽快执行用于循环整个因为它找到一个错误级别大于2如果在列表中五个文件,第三个具有VCS问题 - 脚本唯一手柄在第2位。
SETLOCAL ENABLEDELAYEDEXPANSION
设置file_list中=
FOR / F %%倍In(TEMP.TXT)做(
AccuRev的差异-b%%〜X
IF错误级别2(
与此呼应的文件VCS问题:%%〜点¯x
)ELSE(
设置file_list中=!file_list中! %%X
)
)
I've got a batch file that parses a bunch of file names out of a text file and concatenates them into a single strong - it was previously discussed here. However, I don't want the string to contain a file if the file throw an error when I run it through some command (like a VCS check, for example). Here's my attempt:
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
)
The problem is - the script appears to stop executing the entire for-loop as soon as it finds one errorlevel greater than 2. If there are five files in the list and the third one has a VCS problem - the script only handles the first two.
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
)
)
这篇关于Windows批处理文件ERRORLEVEL问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!