specify environment variables for conf file in windows cmd - windows

My application.conf uses environment variables like this
cassandraUri = ${?DB_CASSANDRA_URI}
I am starting my Play application using the .bat file created by sbt dist. I have specified the value of DB_CASSANDRA_URI both in the .bat file and also in cmd.
set "PSK"="mysecret"
set "ALLOWED_NODES"="localhost"
set "DB_CASSANDRA_URI"="localhost"
set "DB_CASSANDRA_PORT"="9042"
set "DB_KEYSPACE_NAME"="ksname"
set "DB_USERNAME"="cassandra"
set "DB_PASSWORD"="cassandra"
set "EMAIL_SERVER"=""
set "EMAIL_USER"=""
set "EMAIL_PASSWORD"=""
set "MOCK_EMAIL"="true"
But the application still can't read the variables.
Am I setting the variables incorrectly? What is the right way?

Related

Looking for a better way to set up Windows environment variables from batch file after installing a software

I am building a Windows .bat script to automatically compile and install the Geant4 toolkit from CERN (but my following questions are independent of which of software I want to deal with). What I managed to do so far seems to work OK-ish, but I am not satisfied with how the environment variables are set at the end of the script.
To complete the installation, I have to set up environment variables to indicate the path to required data-sets, and C++ include and library directories (I choose to modify the "PATH" variable for these lasts). I want to set them up for the current script (using set command) and for the next executions (using setx command)
The script I am using now to do that is the following:
REM to get the path to directory where this bat file is executed from.
set G4_bat_file_dir=%~dp0
REM set the environement variables for next cmd runs
REM adding to local (temporary) PATH
set G4dataset_RootDir="%G4_bat_file_dir%\install\share\Geant4-10.4.3\data\"
REM adding environment variables for current and next cmd executions
setx G4dataset_RootDir "%G4_bat_file_dir%\install\share\Geant4-10.4.3\data\"
setx G4ABLADATA %G4dataset_RootDir%\G4ABLA3.1
setx G4ENSDFSTATEDATA %G4dataset_RootDir%\G4ENSDFSTATE2.2
setx G4LEDATA %G4dataset_RootDir%\G4EMLOW7.3
setx G4LEVELGAMMADATA %G4dataset_RootDir%\PhotonEvaporation5.2
setx G4NEUTRONHPDATA %G4dataset_RootDir%\G4NDL4.5
setx G4NEUTRONXSDATA %G4dataset_RootDir%\G4NEUTRONXS1.4
setx G4PIIDATA %G4dataset_RootDir%\G4PII1.3
setx G4RADIOACTIVEDATA %G4dataset_RootDir%\RadioactiveDecay5.2
setx G4REALSURFACEDATA %G4dataset_RootDir%\RealSurface2.1.1
setx G4SAIDXSDATA %G4dataset_RootDir%\G4SAIDDATA1.1
set G4ABLADATA=%G4dataset_RootDir%\G4ABLA3.1
set G4ENSDFSTATEDATA=%G4dataset_RootDir%\G4ENSDFSTATE2.2
set G4LEDATA=%G4dataset_RootDir%\G4EMLOW7.3
set G4LEVELGAMMADATA=%G4dataset_RootDir%\PhotonEvaporation5.2
set G4NEUTRONHPDATA=%G4dataset_RootDir%\G4NDL4.5
set G4NEUTRONXSDATA=%G4dataset_RootDir%\G4NEUTRONXS1.4
set G4PIIDATA=%G4dataset_RootDir%\G4PII1.3
set G4RADIOACTIVEDATA=%G4dataset_RootDir%\RadioactiveDecay5.2
set G4REALSURFACEDATA=%G4dataset_RootDir%\RealSurface2.1.1
set G4SAIDXSDATA=%G4dataset_RootDir%\G4SAIDDATA1.1
setx Geant4_DIR %G4_bat_file_dir%\install\lib\Geant4-10.4.3\
REM adding to PATH the paths to libraries and includes for Qt4 and Geant4.
setx PATH "%G4_bat_file_dir%\install\lib;%G4_bat_file_dir%\install\bin;%G4_bat_file_dir%\xerces-c\instal\bin;%G4_bat_file_dir%\xerces-c\instal\lib;%G4_bat_file_dir%Qt4\install\bin;%G4_bat_file_dir%Qt4\install\lib;%PATH%"
The paths %G4_bat_file_dir%\install\lib;%G4_bat_file_dir%\install\bin;%G4_bat_file_dir%\xerces-c\instal\bin;%G4_bat_file_dir%\xerces-c\instal\lib;%G4_bat_file_dir%Qt4\install\bin;%G4_bat_file_dir%Qt4\install\lib being the ones I want to append.
This is a screenshot of the environment variables set-up I get after running the script 2 times :
http://djienne.free.fr/env.png
This is far from ideal, there several things that I am not happy with:
all the paths in the variables get fully expended, and then also the PATH variable gets too long and I get the error "WARNING: The data being saved is truncated to 1024 characters."
If I run the script twice in a row, it produces duplicates in the PATH entries (and everything above the 1024 characters limit is truncated)
also, if I put this code at the end of my main compilation/installation script it gives the error 'setx' is not recognized as an internal or external command, operable program or batch file. and so the environment variables are not created/modified. But if I run this script as a separate .bat file, it works. So there is something I don't understand.
(I specify that I always do "run as administrator" to run the scripts.)
Thanks in advance for the help.
Following the advice from the comments, I built a batch script launch_visual_studio.bat at the top level of my project, to launch Visual Studio with an updated local PATH. The file contains the code:
#echo off
REM Set the environment
set G4_bat_file_dir=%~dp0
set QTDIR=%G4_bat_file_dir%Qt5\qt-5.6.3\
set QMAKESPEC=win32-msvc2015
set Geant4_DIR=%G4_bat_file_dir%install\lib\Geant4-10.4.3\
REM split into two parts for readability
set PATH=%PATH%;%G4_bat_file_dir%install\bin;%G4_bat_file_dir%install\lib;%G4_bat_file_dir%install\include\Geant4
set PATH=%PATH%;%QTDIR%lib;%QTDIR%bin;%QTDIR%include
REM launch visual studio
"%vs140comntools%..\IDE\devenv.exe"
This works for visual studio 2015, but will be different for other versions.
For the environment variables other than PATH, QTDIR and Geant4_DIR, since they have very specific names (G4ABLADATA, G4ENSDFSTATEDATA, ...), it seems fine to set them permanently using setx, as shown previously.

Jmeter 4.0 While opening jmeter.bat from command line showing exception JMETER_HOME environment variable is not defined correctly

C:\apache-jmeter-4.0\bin>jmeter.bat
The JMETER_HOME environment variable is not defined correctly
This environment variable is needed to run this program
JMETER_HOME is set correctly in environment variable.
ApacheJMeter.jar is working fine.
Similar issue found in below link but this also not helping me.
JMETER_HOME environment variable is not defined
You don't need to set JMETER_HOME variable manually, jmeter.bat script should detect it automatically.
Just in case you want to override it for any reason make sure you do this carefully and the variable points to your JMeter installation like:
set JMETER_HOME=C:\apache-jmeter-4.0 pushd %JMETER_HOME% && jmeter.bat
It might also be the case that Windows doesn't have necessary permissions assuming JMeter lives in root of system drive, try running command prompt as Administrator
More information:
Running JMeter
How to Get Started With JMeter: Part 1 - Installation & Test Plans
You don't need to set JMETER_HOME path explicitly under user variables, just add/change under system variables under path variable as your bin path. If you already have earlier version of JMeter just append with latest version. Path looks like : C:\XXX\apache-jmeter-4.0\bin

Set environment variable in nested batch file

I am trying to factor out a piece of a batch file that sets an environment variable to another batch file. This piece is somewhat involved and I would rather not repeat it in multiple batch files. I won't over-complicate this post with the actual code I'm trying to run in the nested batch file, but will provide a simple example that shows what I'm trying to do and reproduces the problem.
Batch1.cmd
cmd.exe /c setvar.cmd abc def
set abc
setvar.cmd
set var=%1
set val=%2
set %var%=%val%
The error returned for "set abc" in Batch1.cmd is this:
Environment variable abc not defined
I imagine cmd.exe starts up a new environment, because on return to Batch1.cmd, the variable does not exist.
Is there a way I can nest a batch file and keep the environment it creates?
The environment block is not shared between processes. As you are starting a new cmd instance a separate environment block is created, changed and destroyed before returning the control to the current batch file, that will not see any change as it was done in a different process.
Use call setvar.cmd abc def to start the nested batch file in the current process.
Use the setx <var> <val> command to set an environment variable more persistently. For example:
setx WEBCAM_ADDR 192.168.0.101
(Note: There is NO equals sign (=) as with the regular set command)
I just went through this issue, trying to run batch files from windows. This is better than having to write, say, a configuration file somewhere...

Setting environment variables via Command Prompt from file

Aside from setting N environment variables using these steps:
Open System Properties
Click Advanced system settings
Click Environment Variables
Create/Update/Delete Environment Variables
Is there a way to set multiple environment variables on a text file and load it on command prompt? The file would look like this:
SET <VariableName>=<PATH>
SET <VariableName>=<PATH>
SET <VariableName>=<PATH>
SET <VariableName>=<PATH>
SET <VariableName>=<PATH>
If so, what command should I run if the file would be saved as EnvironmentVariables.txt

Run Tomcat 7 in Windows from batch file

I need to run Tomcat from within a program. So, I am thinking of having a windows batch file to run the Tomcat. Can you please tell me what commands should be in the batch file to start tomcat 7?
#echo off
pushd "path-to-tomcat-bin-directory"
call startup.bat
Example path-to-tomacat-bin-directory is D:\Java\apache-tomcat-7.0.41\bin\
Also you should already set the JAVA_HOME or JRE_HOME environment variable
To do that
Go to MyComputer->rightclick->properties->Advanced->Environment Variables
Add new User Variable JAVA_HOME
Variable name = JAVA_HOME
Variable value = your_java_home_directory;your_java_home_directory/bin;

Resources