putenv/setenv using substitutions

Posted by vinaym on Stack Overflow See other posts from Stack Overflow or by vinaym
Published on 2010-04-17T19:41:42Z Indexed on 2010/04/17 19:43 UTC
Read the original article Hit count: 370

Filed under:

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?

© Stack Overflow or respective owner

putenv/setenv using substitutions

Posted by vinaym on Stack Overflow See other posts from Stack Overflow or by vinaym
Published on 2010-04-17T19:12:16Z Indexed on 2010/04/17 19:13 UTC
Read the original article Hit count: 370

Filed under:

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?

© Stack Overflow or respective owner

Related posts about c