0

In a batch file I have the following code:

where /R "C:\Program Files (x86)\Java" java.exe

It returns a list of filepaths that contain the java executable application. How can I store the list into a variable?

For example, I was wondering if something will work like this:

set javapath=where /R "C:\Program Files (x86)\Java" java.exe
echo %javapath%

I was hoping it will return C:\Program Files (x86)\Java\jre7\bin\java.exe

but it isn't. Anyone has an answer?

Cao Felix
  • 329
  • 2
  • 6
  • 24
  • What you're trying to capture is the text output of the command, but what you're actually capturing is the exit code. Sadly there's no easy way to capture the text, so you'll have to choose a hard way like redirecting it to a file: http://stackoverflow.com/questions/14952295/set-output-of-a-command-as-a-variable-with-pipes – Alex Fitzpatrick Jun 24 '15 at 18:25

1 Answers1

1
for /f "tokens=* delims=" %%# in ('where /R "C:\Program Files (x86)\Java" java.exe') do set "javapath=%%#"
echo %javapath%
npocmaka
  • 55,367
  • 18
  • 148
  • 187
  • Just an additional question to this one, how can I get the latest modified date of java folder from this list? – Cao Felix Jun 25 '15 at 15:44