嵌套循环variables批处理

这是我的代码

set list=test del /Q failed_tests.txt FOR %%a IN (%list%) DO ( %%a > output_%%a.txt FINDSTR /C:"[----------]" output_%%a.txt > check_run.txt for /f "delims=" %%x in (check_run.txt) do ( set content=%%x ) if not %content%=="[----------]" ( echo Test Does Not Run >> failed_tests.txt ) else ( echo Test Runs >> failed_tests.txt ) ) type failed_tests.txt 

content似乎总是被设置为"[----------]" 。 但是,当output_test.txt / check_run.txt不包含"[----------]" ,应将其设置为空string。

将@ JosefZ的建议合并到一个答案中,所以这显示了答案。

 SETLOCAL ENABLEDELAYEDEXPANSION set list=test del /Q failed_tests.txt FOR %%a IN (%list%) DO ( %%a > output_%%a.txt FINDSTR /C:"[----------]" output_%%a.txt > check_run.txt set "content=" for /f "delims=" %%x in (check_run.txt) do ( set "content=%%x" ) if not "!content!"=="[----------]" ( echo Test Does Not Run >> failed_tests.txt ) else ( echo Test Runs >> failed_tests.txt ) ) type failed_tests.txt 

编辑:保留警告双引号根据评论。