سؤال

I am trying to write a script that will check another batch script setup for a tool I am running.

Inside the batch file to be checked is the line: set tooldir=D:\Folder

I want to be able to pull 'D:\Folder' out and check its validity, but I cannot even get my variable to store the right string.

As of now I have:

for /F "delims=" %%a in ('findstr /L tooldir= %batFileName%') do set batToolDir=%%a
echo %batToolDir%

Which outputs

C:\Users\me>for /F "delims=" %a in ('findstr /L tooldir toolBatch.bat') do set batToolDir=%a
C:\Users\me>set batToolDir=set tooldir=D:\Folder
C:\Users\me>set batToolDir=cd %tooldir%
C:\Users\me>echo cd %tooldir%
cd %tooldir%

It is setting my output variable twice, the first time is correct and then for some reason it does set batToolDir=cd %tooldir%

هل كانت مفيدة؟

المحلول

I'm not sure what your test data is but use quotes like this, to protect against spaces and things like the = in tooldir= in your case:

for /F "delims=" %%a in ('findstr /L "tooldir=" "%batFileName%" ') do set "batToolDir=%%a"
echo "%batToolDir%"
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top