Set= log.txt in batch

2019-07-14 17:27发布

I have like a log.txt file which contains:

MyName

My batch:

@echo off
set name= [log.txt]

in the [log.txt] part, it should read 'MyName' from the log.txt file, to set it as 'name'.

How?

2条回答
对你真心纯属浪费
2楼-- · 2019-07-14 18:00

You can also use

set /p name=<log.txt

which might be considered shorter and a little less ugly.

查看更多
唯我独甜
3楼-- · 2019-07-14 18:02

In cmd.exe, there's only this ugly way:

@echo off
for /f "usebackq tokens=* delims=" %%i in ("log.txt") do (
    set name=%%i
)
查看更多
登录 后发表回答