3

Say for example in Control Panel\System and Security\System > Advanced System Settings > System Properties > Advanced Tab > Environment variables...

I have the following PATH:

Value 1:

PATH=%JAVA_HOME%\bin;e:\Groovy\GROOVY~1.0\bin;E:\Python;C:\Users\MyName\AppData\Local\GitHubDesktop\bin;%PYTHON3_HOME%;%GROOVY_HOME%\bin;

when in cmd, I do:

echo %PATH%

then I get:

Value 2:

E:\Program Files\Java\jdk1.8.0_151\bin;e:\Groovy\GROOVY~1.0\bin;C:\Users\MyName\AppData\Local\GitHubDesktop\bin;E:\Program Files\Python\Python36-32;E:\Program Files (x86)\Groovy\Groovy-2.6.0\bin; 

Then what command in cmd will be able to print out same exact PATH values with variable names (%JAVA_HOME% etc.) as from the System Properties (Value 1)?

Learning Spirit
  • 73
  • 1
  • 1
  • 12
  • 1
    The __local__ `PATH` in a running command process contains the folder paths always with environment variable references expanded. The variable expansion is done already by Windows before starting `cmd.exe`. See [Why are other folder paths also added to system PATH with SetX and not only the specified folder path?](https://stackoverflow.com/a/25919222/3074564) for an example how to retrieve the __system__ `PATH` directly from Windows registry using `reg query`. – Mofi Jul 24 '18 at 05:48
  • Please take also a look on [What is the reason for '...' is not recognized as an internal or external command, operable program or batch file?](https://stackoverflow.com/a/41461002/3074564) – Mofi Jul 24 '18 at 05:48

2 Answers2

3

The set <variableName> command shows variables without interpreting the content.
Or you can ise delayed expansion for that, too.

setlocal EnableDelayedExpansion
echo !path!

but in your case, the expansion in echo %path% will not expand any further percent parts in the content of PATH (you get only problems with other characters like &|<>)

The content is already expanded after you set the path with set PATH=%JAVA_HOME%\bin.

When you set the percent part instead of the expanded version, then the PATH searching doesn't work anymore, as cmd.exe would try to search in the literal path of %JAVA_HOME%

To get the definition of the PATH from the System Properties can be retrieved from the registry via REG QUERY.

User variables with

reg query HKEY_CURRENT_USER\Environment /v path  

And the system variables with

reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v path
jeb
  • 78,592
  • 17
  • 171
  • 225
0

From cmd, try this :

powershell gci env:<name_variable>

Example : powershell gci env:Path

If you want all variables name starting (or finishing) with Path just add * after (or before) your variable name.

Example : powershell gci env:*Path*

:-)

Bk01
  • 1
  • 1