1

I am executing a perl script on windows, using a batch script. I am setting below variable in batch script:

SET PATH_VAR=C:\Users\

I am able to access PATH_VAR in perl as below:

my $path1 = $ENV{'PATH_VAR'}

I would like to also export environment variables set in perl to batch. Like the inverse of what I am doing now. Is there a way to do that?

PS: I tried this, but it doesn't work:

$ENV{'PATH_Z'}="Hello World";

2 Answers 2

6

Changes to environment variables can not effect the parent process, it's part of how they work, so nothing you do in the Perl script can change the environment variables of the batch script. However any child process, started with exec(), system() or `` will see the changes you made in the Perl script.

Sign up to request clarification or add additional context in comments.

Comments

5

The only way to do this is to have the Perl script output shell statements, and for the shell to evaluate the output.

Bash example:

$ export FOO=123
$ echo $FOO
123
$ perl -e 'print "export FOO=456\n"' ; echo $FOO
123
$ $(perl -e 'print "export FOO=789\n"') ; echo $FOO
789

Edit: I see OP is using Windows, so this answer doesn't apply :-(

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.