Re: Windows environment variable not set if calling from a perl program (goto :end)
by tye (Sage) on Dec 08, 2015 at 01:52 UTC
|
| [reply] |
|
|
This will work if an existing variable needs to be modified. My problem is that I want to set a new environment variable by invoking a batch file from a perl script. I don't know what's inside batch file before invoking the batch file. So I cannot use work around of $ENV{'envvariable'} = 'soandso'; in perl.
I also tried pl2bat function converting my whole perl script to a batch file, it ran successfully but the behavior of environment variables is the same as before. The enviroment variables are not set.
| [reply] |
|
|
I did not say it solved your problem; I said that it shows how you can accomplish this.
It sounds like the easiest solution (given that you are so reluctant to admit that you can read the contents of your setEnv.bat) would be to add "call setEnv.bat" to the preamble that pl2bat would add to your Perl script.
| [reply] |
|
|
|
|
|
|
| [reply] |
|
|
|
|
|
Re: Windows environment variable not set if calling from a perl program
by NetWallah (Canon) on Dec 08, 2015 at 06:18 UTC
|
Instead of "set TEST", use "setx", as explained in this stackoverflow article.
Our business is run on trust. We trust you will pay in advance.
| [reply] |
|
|
That is not doing what the OP is expecting; and could cause mysterious problems.
Rather than simply modifying the current session's environment; it makes persistent changes to the system registry. Which is fine if that is the intent; but dangerous if not.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |
|
|
Sorry, that won't work in my use case. I dont' want to set system-wide envs.
| [reply] |
Re: Windows environment variable not set if calling from a perl program
by BrowserUk (Patriarch) on Dec 09, 2015 at 05:49 UTC
|
| [reply] [d/l] |
|
|
Thanks. Unfortunately not everybody who writes those batch scripts can write perl scripts. What I am doing for now is I have a windows batch script which calls perl program periodically ( basically perl became an utility now rather than the driving program ) the batch script is the driving program now. In this case I can set env variables. But yes writing such a complex program in batch is excruciatingly painful. I find it very easy in Perl.
| [reply] |