REM run the script that sets environment variable FOO
call foo.bat
REM now %FOO% is set in the environment
REM Corion;s suggestion: if you need the entire environment
REM set called by itself dumps one line each VAR=VALUE
set
####
REM run the script that sets environment variable FOO
call foo.bat
REM now %FOO% is set in the environment
REM my suggestion: send just a few to stdout
echo FOO=%FOO%
echo BAR=%BAR%
####
use strict;
use warnings;
#backticks convert anything sent to stdout into a string
#so this should fill $sEnvironment with assignments
my $sEnvironment=`wrapper.bat`
#now parse $sOutput and store the various VAR=VAL pairs
my @aAssignment=split(/[\r\n]+/,$sEnvironment);
foreach my $sAssignment (@aAssignment) {
$sAssignment =~ /^(\w+)=(.*)$/;
$ENV{$1}=$2;
}