Reading the content of a text file into an environment variable
Actually I want to pas the content of txt file to if condition
I am trying the following
set /p var = < file name
if not %var% == “str开发者_JAVA百科ing” goto x else goto y
But it's not working .
When I check value of var it shows variable not defied
Set %var%
Environment variable %var% not defined
echo sometext > testfile.txt
set /P someVar=<testfile.txt
if %someVar%==sometext (echo true) else (echo false)
From what I understood, this is the example to be based on.
I think you want
echo %var%
to show the current contents of the variable var
.
now it's working. I was using space in set variable cmd.
set /P someVar=< file.txt
if "%someVar%"=="some text" (echo true) else (echo false)
It may be worth noting that "%var%"
has to be in quotes. If you leave %var%
without quotes and %var%
contains string
your statement becomes:
if not string == "string" goto x else goto y
精彩评论