Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-04-23 18:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found