这是我的代码
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
不包含"[----------]"
,则应将其设置为空字符串。
答案 0 :(得分:1)
将@ 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
修改:根据评论保留警示性双引号。