tags:

views:

295

answers:

2

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  A: 

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

@echo off
for /f "usebackq tokens=* delims=" %%i in ("log.txt") do (
    set name=%%i
)
grawity
You can cut the usebackq and tokens options from there, by the way, as you're not using them.
Joey
This is too much work, above seems to be easier.
YourComputerHelpZ
+5  A: 

You can also use

set /p name=<log.txt

which might be considered shorter and a little less ugly.

Joey
Hmm, why did this fail for me last time I tried :/
grawity
Dunno :-). Both methods work actually, but have different effects with files containing more than just one line.
Joey
it works for me so it's fine, this is a lot less stuff.
YourComputerHelpZ
Nice. We don't get to be able to feed stdin with files very often with cmd compared to bash, I'll remember this one.
Jay