【发布时间】:2015-08-22 12:00:12
【问题描述】:
我正在修改批处理脚本以将文件位置传递给 makefile(使用 nmake 运行)。 for 循环应该循环可用驱动器并搜索文件(如果之前没有设置)。批处理不是我有太多经验的东西,所以希望有人能发现发生了什么。
当我在遍历驱动器的 for 循环之外设置 winbison 时,变量将设置为 win_bison.exe 的路径。当我在 for 循环中设置它时,我得到“ECHO 开启”。我认为这是批处理如何处理解析/扩展的一个症状。我设置了 EnableDelayedExpansion 但得到了相同的结果。
这是我的代码。
@ECHO OFF
setlocal EnableDelayedExpansion
set currentDir=%cd%
set winbison=
set winflex=
set drives=
for /f "delims=" %%a in ('fsutil fsinfo drives') do @set drives=%%a
REM :~8 is to slice off "Drives: " returned by fsutil
for %%i in (%drives:~8%) do (
chdir /d %%i
if not defined [%winbison%] (
set winbison=
for /f "delims=" %%a in ('dir win_bison.exe /s /b 2^>nul') do @set winbison=%%a
@ECHO ON
echo test
echo %winbison%
@ECHO OFF
)
if not defined [%winflex%] (
set winflex=
for /f "delims=" %%a in ('dir win_flex.exe /s /b 2^>nul') do @set winflex=%%a
)
)
chdir /d %currentDir%
@ECHO ON
echo %winbison%
... stuff gets passed to nmake.
【问题讨论】:
-
也许this可以帮助你
标签: batch-file