set batch variable to value from text file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Locked
Message
Author
Ted Turner
Posts: 2
Joined: 19 Jul 2012 10:51

set batch variable to value from text file

#1 Post by Ted Turner » 19 Jul 2012 10:58

How do set batch variable to value from text file?

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: set batch variable to value from text file

#2 Post by Squashman » 19 Jul 2012 11:03

If it is the first line of the text file.

Code: Select all

set /p value=<myfile.txt

Ted Turner
Posts: 2
Joined: 19 Jul 2012 10:51

Re: set batch variable to value from text file

#3 Post by Ted Turner » 19 Jul 2012 11:18

Code: Select all

C:\test>type sman.bat
@echo off
echo DosMaster > sman.txt
set /p var=<sman.txt
echo var=%var%
C:\test>
C:\test>sman.bat
var=DosMaster

C:\test>

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: set batch variable to value from text file

#4 Post by foxidrive » 19 Jul 2012 11:21

DosMaster has a trailing space, if it matters :)

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: set batch variable to value from text file

#5 Post by Ed Dyreen » 19 Jul 2012 12:58

'
Didn't I ban you billrich, TB99 or whatever it will be next, we are not idiots.

Locked