I have this in a batch file called find_java.bat:
@echo off
for /f "delims=" %%a in ('C:\Programming\Android\android-sdk\tools\lib\find_java.exe') do (set java_exe=%%a)
The problem is that when I run this batch file I get:
'C:\Programming\Android\android-sdk\tools\lib\find_java.exe' is not recognized as an internal or external command, operable program or batch file.
However when the batch file contains just:
@echo off
C:\Programming\Android\android-sdk\tools\lib\find_java.exe
it executes the command just fine.
I’m new to writing batch files, but looking at online examples this should work…
Edit:
Sorry for revisiting this so late.
I found the solution. It had something to do with ComSpec for reasons I still don’t quite understand. My ComSpec was
%SystemRoot%\system32\cmd.exe;
I went into the registry and changed
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\ComSpec
from
%SystemRoot%\system32\cmd.exe;
to
C:\Windows\system32\cmd.exe
then logged out and back in and magically it worked. %SystemRoot% was C:\Windows, all the other system variables use it, and
@echo off
for /f "delims=" %%a in ('"C:\Programming\Android\android-sdk\tools\lib\find_java.exe"') do (set java_exe=%%a)
worked perfectly, so I honestly don’t understand but see Command Line FOR /F Fails to possibly make more sense of it than I did.
Normally these problems are solved by enclosing the command in double quotes.
But I don’t see anything in your command that would require quotes.
I haven’t a clue why it is not working, but the FOR /F statement is attempting to execute the command in a new CMD shell.
Try to run the following batch and see if it runs the command OK. This is the command that the FOR statement is actually attempting to run:
If that runs OK, then I am completely stumped. If it fails, then figuring out why should also help diagnose why the FOR /F command is failing.