set environment in perl through windows

S

Slickuser

I want to set a permanent environment on Windows and use it right
away.
None of this work, any help?

system("SET A=c");
system("SETX AB BN");

system("echo %A%");
print $ENV{'A'} . $ENV{'AB'};

From the above script.. i got nothing print out

Output:
%A%
 
J

Jürgen Exner

Slickuser said:
I want to set a permanent environment on Windows and use it right
away.
None of this work, any help?

system("SET A=c");

Starts a new process, executes the SET command in that process, and then
terminates that process.
system("SETX AB BN");

Starts a different new process, executes the SETX command in that
process, and terminates that process.
system("echo %A%");

Starts yet a third new process, executes the echo command in that
process, and terminates that process.
print $ENV{'A'} . $ENV{'AB'};

And then prints the values of the environment variables A and AB as they
are set in the process, which is executing the Perl program and which
has nothing to do with the three earlier child processes..

If you want to set an environment variable in your Perl program/Perl
process then just do so:

$ENV{'A'} = 'c';
$ENV{'AB'} = 'BN';

Of course these settings will not be inherited by the parent process,
i.e. by the process that initiated the Perl process. If that's what you
had in mind then I suggest to consult
perldoc -q environment

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top