How can I execute code saved in a variable? I'm trying to execute an if statement that I have saved in another file (that must remain a text file). Clues on how to execute an if
statement just from a variable might help, as I assume the problem is that it can't read the %%s
.
Text file contains:
if %var%==0301 (echo Yay)
Batch file contains:
for /f "tokens=*" %%s in (code.file) do (
%%s
)
This normally executes the code in code.file
by setting everything in code.file
to the variable %%s
and then executing the variable.
The result is this: 'if' is not recognized as an internal or external command, operable program or batch file.
This method works for executing echo
and set
, but I need it to work for if
.