Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass %ENV to and from a .exe

Status
Not open for further replies.

CJason

Programmer
Oct 13, 2004
223
0
0
US
I have an evironmental variable that I set in perl, $ENV{HELLO} = 1. I want to call (system or `) an executable that will read and/or set this to a different value. It seems that the initial read works, but the setting appears to only be set for the .exe's children and not visible to the calling perl script.

Is there a way to make this work? That is, ensure that the perl script "sees" the changes made to $ENV within the executable?

FYI: There may be many variables passed in/out that I want to be able to do this with (i.e., not just ONE).

Thanks much!
 
Use shared memory instead of trying to set system variables.


I would assign a static GLUE variable and make sure you can't kill your script with out destroying the shared memory. If you used a dynamic glue I would have a check that watches semaphore usage on the server until you get the hang of what your doing :)




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Child processes can't change the environment variables of the caller, and they are like that for a reason.

Alternatively come up with a design that doesn't rely on global variables in this insecure way. Rather than setting the global variable in the child process, return the value to the caller and make the caller responsible for setting the ENV variable.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top