Saumil
Saumil

Reputation: 2517

How to set an environment variable with the value that return in a text file?

The text file will be having just one word("1234" or "password" ), now I'm looking for a way to give this content of the text file to an environment variable

Upvotes: 1

Views: 871

Answers (2)

jeb
jeb

Reputation: 82247

If you only want to read one line you can also use set /p.

<myFile.txt set /p var=
echo %var%

Upvotes: 4

anishsane
anishsane

Reputation: 20980

Use below for loop syntax. Replace filename with your filename, or environmental variable. If this code is supposed to be put inside a batch file, replace % with %%, as %%t.

for /F %t in (filename) Do (
    echo %t
    :: Do whatever else you want to do with %t
)

Upvotes: 2

Related Questions