Wednesday, 15 February 2012

Get System Environmental Variables In C -


I have written an application in C. That is to read the environmental variable and to handle those changes appropriately. When the application starts up, I set "code" setenv ("MYVARIABLE", "TEST", 1) to set it. To move on and start the variable (to prevent any empty signal) P>

This app often gives an edge and, during those loops, one of its jobs is that getenv ("MYVARIABLE") c2 ) I will run like a command:

  MYVARIABLE = "my new value"    

or

  export MYVARIABLE = "my new value"   

My application does not have to catch environmental updates Looks though, though. Instead, it is emphasizing that MYVARIAABLE is not "test," and "my new value". I'm not sure why these two environments are different, but I need to work them together. Does anyone know what I am doing wrong?

My system is running Archlinux for anyone who is

The problem you are facing now is that you have set your variable only within the scope of the local peak session EX:

(when you define a variable):

  MYVARIABLE = "My new value"   

This only affects the current shell, when you set it as:

  Export MYVARIABLE = "My new value"   

This effect to the current shell The does and starts all procedures from the current shell.

If you set it to your .bashrc file, it will permanently set it for all future sessions, but you will be able to source that file to work in your current session. Will be required. / P>


The best solution is to close a process, for example if your program is called a.out you can execute: < Pre> & gt; .aaout & amp;

This will continue to work in the shell session, while the program is running, you can set the variable in the same session.


I have ever seen the other option, to force my shell session to "auto" sources like things, to emphasize them:

1) Your first Sign in session:

  trap 'source ~ / .bashrc' DEBUG   

2) Then start your program in the same session:

 . / A.out   

3) To add a new env var to another window source, edit your .bashrc file in a second window. File:

  source ~ / .bashrc   

Now the new windows that are running in your program have set new variations for their session. I have used it before and I know that it works, but I have never applied it to the applications already created. But I suspect that this should work for you.

No comments:

Post a Comment