Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Issue with env variables set through dos batch

by moritz (Cardinal)
on Oct 13, 2011 at 15:44 UTC ( #931286=note: print w/ replies, xml ) Need Help??


in reply to Issue with env variables set through dos batch

I'm not really familiar with DOS batch files, but on linux a shell script (the equivalent to a batch file) is run in a new process. And when the process exits, its environment variables vanish with it.

There you need to launch the perl script that is supposed to see the environment variables from within the shell script, so that it is a subprocess of the shell which holds the interesting environment variables.

To check if that's the case in DOS/Windows too, simply inspect the environment variables on the dos prompt after you ran the batch file.


Comment on Re: Issue with env variables set through dos batch
Re^2: Issue with env variables set through dos batch
by Marshall (Prior) on Oct 13, 2011 at 15:51 UTC
    There is no DOS anymore.

    The Windows command prompt is like one of the ~unix shells. for example:

    #------------------------------------------ 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 = "/"; } #------------------------------------------
    is not needed!

    pathSeparator of "/" works on Windows and ~Unix (LINUX, etc..)

    Where it really matters, the logic above to determine the OS is woefully inadequate.

      I really appreciate your input..however it does not answer my question on the environment variables. I'm not really concerned about the part of the perl script with the check for the os...I'm not using that $pathSeparator variable anywhere.
Re^2: Issue with env variables set through dos batch
by akrrs7 (Acolyte) on Oct 13, 2011 at 16:10 UTC
    Very true...that is exactly the behavior I'm observing in the windows cmd window. How do I get the env. variables to stay put ? Running the perl script from a batch script is not right now an option for me.
      In general if you set ENV variables in a shell and then launch a program from that shell's environment, the program will inherit the environment variables.

      I you want some ENV variables to apply to any command line window, Go to Control Panel|System|Environment Variables, change them and then set them "to apply to all future command line windows". This is for example, how you would set "PATH" to be persistent.

      If this is a "one off" thing, then I would pass special settings as part of @ARG.

Re^2: Issue with env variables set through dos batch
by ikegami (Pope) on Oct 13, 2011 at 16:45 UTC
    While environment variables are inherited from parent to child like in Linux, a batch files are run more like source foo.bat than cmd /c foo.bat when possible (when the parent is cmd).

        The parent is perl, which can't execute batch files, so a cmd is indeed launched here.

        I wasn't so much correcting you as explaining that the behaviour is different than explained when the batch file is run from the prompt.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://931286]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2014-09-24 04:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (245 votes), past polls