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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting Windows variables from within a Perl script

Status
Not open for further replies.

Winstonb

Technical User
Joined
Aug 11, 2001
Messages
29
Location
GB
Hello,

New to Perl and trying to set Windows variables from within Perl.

eg; set JAVA_HOME=C:/java

Does anyoneone know how this could be invoked via a perl script ?

Thanks in advance
Winston
 
I've needed this same functionality myself several times and ended up using work arounds. Re-investigating came across the following:


It involves interacting with window's registry. I haven't tried it but looks promising. One note, each process of windows opens it's own copy of the current environment. If a process is running in window 'A' and the registry later changed in window 'B', window A will not acknowledge the changes unless the program running in that window requests an update. If you're just after temp changes to subprocesses within your process and subsequent spawned/forked processes, you can always modify %ENV.
 
Thanks for that,

I have however stumbled across this, which seems to do the trick...

$ENV{'PATH'} = 'C:/mypath';
 
That would be modifying %ENV now wouldn't it?!? :o

Did a quick test under WinXP and observed that while you can change ENV{PATH} within the program, it reverts back to what the parent process has defined as ENV{PATH} once the program exits. The goal of the registry hack would be to alter subsequent spawned processes. My intent was to use this as a cheap way to pass information between otherwise non-friendly programs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top