Reading the content of a text file into an environ

2019-08-14 03:33发布

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% == “string” 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

4条回答
forever°为你锁心
2楼-- · 2019-08-14 03:38

I think you want

echo %var%

to show the current contents of the variable var.

查看更多
放我归山
3楼-- · 2019-08-14 03:40

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

查看更多
Melony?
4楼-- · 2019-08-14 03:50

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)

查看更多
狗以群分
5楼-- · 2019-08-14 03:58
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.

查看更多
登录 后发表回答