in reply to Getting the ENV from the .bat file
Forgive me if I am confusing you with someone else, but didn't we discuss this a few days ago in the chatter box? If so, I know it is sometimes hard to follow what is happening in the chatterbox, so I'll repeat here what we suggested. If I recall, the batch file is something you inherited and can't change. So we suggested that you wrap the batch file in a second batch file that looks something like this:
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
If dumping all environment variables is too much, you could just dump selected environment variables like this:
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%
Then in your Perl script, you call your second batch file like this:
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; }
Did you try that? What problems did you find?
Best, beth
Update: fixed error in call to foo.bat, identified by Corion via private message.
|
|---|