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.


In reply to Re: Getting the ENV from the .bat file by ELISHEVA
in thread Getting the ENV from the .bat file by sowndarr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.