user7668768
user7668768

Reputation:

How to set a variable that is saved on another file in batch

Okay, so I want to be able to set my variable "EQP1" to whatever "chareqp1.txt" has printed in it. I have this, but it doesn't work, when I echo the variable it is saved as the text "C:\Users\Slots\Slot1\chareqp1.txt".

set /a "EQP1=C:\Users\Slots\Slot1\chareqp1.txt"

What's wrong with it?

Upvotes: 0

Views: 61

Answers (2)

user6811411
user6811411

Reputation:

You are using the wrong parameter, it's set /p and you need redirection to read the first line from a file.

set /p "EQP1=" <"C:\Users\Slots\Slot1\chareqp1.txt"

If it's not the first line you'll have to parse the file with for /f and maybe findstr

Upvotes: 1

Compo
Compo

Reputation: 38614

Use set /p instead of set /a

Set /P "EQP1="<"C:\Users\Slots\Slot1\chareqp1.txt"

Upvotes: 1

Related Questions