为什么环境变量使用SETENV后未设置() [英] Why the environment variable is unset after using setenv( )
本文介绍了为什么环境变量使用SETENV后未设置()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了Linux的C程序使用来设置环境变量的值 SETENV
,但执行后,当我运行设置
或导出
环境变量本身似乎被取消设置。为什么?
下面是code片断:
INT的main()
{
字符* mallocPtr,* callocPtr,* reallocPtr,* memalignPtr,* vallocPtr;
结构sigaction的SA; sa.sa_handler = SIGSEGV_handler;
的sigaction(SIGSEGV,&安培; SA,NULL); 如果(SETENV(ENV1,3,1)== 0)
的printf(ENV1设置为3 \\ n);
其他
fprintf中(标准错误,SETENV失败的ENV1);
解决方案
环境变量程序的范围内设定。
当你的程序退出时,你回来从你的程序启动那里的环境。
I wrote a C program in Linux to set the values of environment variables using setenv
, but after execution, when I run set
or export
, the environment variable itself seems to be unset. Why?
Here is the code snippet:
int main()
{
char *mallocPtr, *callocPtr, *reallocPtr, *memalignPtr, *vallocPtr;
struct sigaction sa;
sa.sa_handler=SIGSEGV_handler;
sigaction(SIGSEGV, &sa, NULL);
if(setenv("ENV1", "3", 1) == 0)
printf("ENV1 set to 3\n");
else
fprintf(stderr, "setenv failed on ENV1");
解决方案
The environment variables are set within the context of your program.
When your program exits, you're back in the context from where your program was started.
这篇关于为什么环境变量使用SETENV后未设置()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文