In Windows 7, when I start the Command prompt, is there any command to display the contents of an environment variable (such as the
I have tried with
echo PATH and
$PATH but none of these work.
In Windows Command-Prompt the syntax is
To get a list of all environment variables enter the command
To send those variables to a text file enter the command
For me the solution was a bit diferent, it won't recognize the system environment variable JAVA_HOME, i had to set JAVA_HOME as User environment variable, so that i can use %JAVA_HOME% in system environment variable setting up.
Resuming, I had to:
-add a user environment variable: %JAVA_HOME% as:
-add to %PATH% system environment variable:
-latter on command line:
echo %JAVA_HOME%, and it retrieved the correct path (before it wasn't recognizing); echo %PATH%, and it retrieved the "C:\Program Files\Java\jdk1.8.0_25\bin" composed with %JAVA_HOME% user variable;
And it worked for me, hope it helps!!
As an additional bit of information: While SET works with global or system variables, sometimes you want to write and read User variables, and this is done with the SETX command. SETX is included in the base installs of Windows beginning with Vista, but was also available in Windows XP by installing the Resource Pack.
One difference about SETX though is that you cannot read the variable out in the same command window you wrote it in. You have to write the SETX command in one Command or Powershell window, and then open a new window to read it using ECHO.
SETX can also write global or system variables.
To Set a user variable using SETX:
To set a global or system variable using SETX:
To read a user or global variable:
Remember, you must open a new Command or Powershell window to read this variable.
From SET /?:
So for example if you want to find value of environment variable %PATH%, you can just type
This is 3 characters shorter than
To complement the previous answer, if you're using Powershell
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site.
Would you like to answer one of these unanswered questions instead?