This is my dos batch script:
@echo off @set SCRIPTDIR=%~dp0 @for /f %%I in ("%SCRIPTDIR%\.") do @set BingApps=%%~dpI @for /f %%I in ("%BingApps%\.") do @set BingAppsHome=%%~dpI @for /f %%I in ("%BingAppsHome%") do @set myDRIVE=%%~dI @set SCRIPTDIR=%SCRIPTDIR:~0,-1% set SCRIPTDIR set BingApps @for /f %%I in ("%BingAppsHome%") do @set BingTcEnv=%%~nI @set TEMP=%DRIVE%\temp @set THIS_HOME=%DRIVE%\thisHome @set thisRoot=%BingAppsHome%\thisRoot @set thisData=%BingAppsHome%\thisData set thisData echo doneDosTest
This is my perl script
use strict; use warnings; use File::Find; use File::Spec; use File::Path; use File::Copy; use File::Basename; use Cwd; my $scriptDir = cwd; #------------------------------------------ my $operatingSystem = $^O; my $windows = "MSWin32"; my $unix = "hpux"; print "Running under ${operatingSystem} environment.\n\n"; my $pathSeparator = ""; if ( $operatingSystem eq $windows ) { $pathSeparator = "\\"; } else { $pathSeparator = "/"; } #------------------------------------------ #execute the environment variables script if ( $operatingSystem eq $windows ) { system("$scriptDir/dosTest.bat"); } else { system("$scriptDir/unixTest.sh"); } #---------------------------------------------- $ENV{'ksENV'} = "c:/temp"; $ENV{'script_dir'} = "$ENV{'ksENV'}/bin"; my $someFile = "$ENV{'ksEnv'}/bin/someFile.txt"; open theFile, $someFile or die $!; while (my $record = <theFile>) { print $record; } close(theFile); print "\n$ENV{script_dir}"; print "\n$someFile"; print "\n$ENV{THIS_HOME}"; print "\n$ENV{thisRoot}";
When the perl script is executed the final two print statements for printing the environment variables set by the dos script return this: Use of uninitialized value $ENV{"THIS_HOME"} in concatenation (.) or string at perltest.pl line 50.... The 'set' statements in the dos script execute fine..they return the value of the environment variables that I expect to see. I would've expected the environment variables set by the dos script to stay put in the cmd window - but they don't. Please advise on what I could be doing wrong here. Thanks...

In reply to Issue with env variables set through dos batch by akrrs7

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.