0

I am trying to find the path of Java in the system using this command.

where /r "c:\Program Files (x86)\Java" java.exe 

Now I want to set the out put of the where command to a variable so that i can use it later in a batch file.

I tried using

set JAVA_PATH = where /r "c:\Program Files (x86)\Java" java.exe

But that doesn't seems to work.

Any help highly appreciated.

Squashman
  • 13,649
  • 5
  • 27
  • 36
Easy Coder
  • 295
  • 1
  • 3
  • 14

1 Answers1

0

You could push the results of that command to another batch file and use the call function to call those results and then iterate through those results using FOR.

The code to output to another batch file would look like this:

where /r "c:\Program Files (x86)\Java" java.exe > path.bat

EDIT: The resulting path.bat file looks like this:

c:\Program Files (x86)\Java\jdk1.7.0\bin\java.exe
c:\Program Files (x86)\Java\jdk1.7.0\jre\bin\java.exe
c:\Program Files (x86)\Java\jdk1.7.0_51\bin\java.exe
c:\Program Files (x86)\Java\jdk1.7.0_51\jre\bin\java.exe
c:\Program Files (x86)\Java\jdk1.8.0_144\bin\java.exe
c:\Program Files (x86)\Java\jdk1.8.0_144\jre\bin\java.exe
c:\Program Files (x86)\Java\jdk1.8.0_181_32b\bin\java.exe
c:\Program Files (x86)\Java\jdk1.8.0_181_32b\jre\bin\java.exe
c:\Program Files (x86)\Java\jdk7\bin\java.exe
c:\Program Files (x86)\Java\jre1.8.0_144\bin\java.exe
c:\Program Files (x86)\Java\jre1.8.0_181\bin\java.exe
Zach Pedigo
  • 396
  • 2
  • 9