Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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

Replies are listed 'Best First'.
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.

Re^2: Issue with env variables set through dos batch
by Marshall (Abbot) 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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://931286]
NodeReaper sharpens his wit

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (11)
As of 2017-08-21 08:51 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (319 votes). Check out past polls.