Jump to content

Batch: Text file -> Environment variable?


Recommended Posts

Posted

Have an INI file with contents like:

 

Alice=One2Three
Bob=Four5Six

 

I want to pick one entry e.g. Bob and put it in an environment variable. This works:

 

for /f "usebackq tokens=2 delims==" %%i in (`findstr Bob file.ini`) do set Bob=%%i

 

 

Took me a teensy while to arrive there having first failed with other approaches. Has anyone ever got "other approaches" to work or is this pretty much what you have to do?

Posted
That's pretty much exactly how I'd do it... What other approaches did you try? Would be interesting to see if there's anything which could be hacked around a bit another time.
Posted
What other approaches did you try?

 

Oh I had loads of fun trying and failing to pipe and redirect the output of 'find' or 'findstr' to 'set' etc.

 

Suspect my heart is stuck in early DOS days because "for /f.." just feels more complicated.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...