putenv/setenv using substitutions
- by vinaym
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
1. Check each line for % characters.
2. Get the text between 2 consecutive % characters.
3. Call getenv using the text from step 2.
4. Replace value obtained above into the line and then call putenv.
Is there a better way to do it?