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

发布于 2024-08-06 04:59:40 字数 649 浏览 4 评论 0原文

我有一个批处理文件,它从文本文件中解析出一堆文件名并将它们连接成一个强文件 - 之前已经讨论过 此处。但是,如果当我通过某些命令(例如 VCS 检查)运行该文件时抛出错误,我不希望该字符串包含该文件。这是我的尝试:

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 问题 - 仅脚本处理前两个。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

远昼 2024-08-13 04:59:40
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
    )
)
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
    )
)
成熟的代价 2024-08-13 04:59:40

IF ERRORLEVEL 构造有一个
奇怪的功能...它返回 TRUE 如果
返回码等于或更高
超过指定的错误级别。

请参考此链接了解如何处理该“功能”。

IF ERRORLEVEL construction has one
strange feature... it returns TRUE if the
return code was equal to or higher
than the specified errorlevel.

Reference this link to understand how to deal with that "feature".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文