vinaym
vinaym

Reputation: 467

putenv/setenv using substitutions

I need user to define all the environment variables needed for my program in a text file as shown below.

MyDLLPath = C:\MyDLLPath
MyOption = Option1
PATH = %MyDLLPath%;%PATH%;

In my program I read each line and call putenv with the string. Problem is that the environment substitutions (%MyDLLPath%) are not being expanded. I am guessing the following fix for that
- Check each line for % characters.
- Get the text between 2 consecutive % characters.
- Call getenv using the text
- Replace value obtained above into the line and then call putenv.

Is there a better way to do it?

Edit: Starting with windows platform. Will have to do unix but not sure how to deal with unix syntax for the substitutions.

Upvotes: 2

Views: 519

Answers (1)

Philipp
Philipp

Reputation: 49850

You could use ExpandEnvironmentStrings.

Upvotes: 2

Related Questions