this is a batch to detect java, but always set ok
setlocal EnableDelayedExpansion
for /f "tokens=3" %%i in ('java -version 2^>^&1 ^| findstr /i "version"') do (echo %%i)
IF %%i == "" (echo fail) else (echo ok)
How do I modify this script so that if java is not installed on the system (32 or 64 bits or both) "echo FAIL" and if it is installed (32 or 64 bits or both) "echo OK"
PD: If it doesn't work properly with the above, I would also accept responses with this command (or any other):
wmic product where "name like '%%java%%' AND NOT Name like '%%java auto%%'"
PD: I have found a batch that does just what I want, but it is long and complicated, and I have not been able to simplify it. I make it available to give solution ideas
Best Answer
For the case you describe, you should use the
where
command coupled with checking the exit code (ERRORLEVEL) to see if the program exists and is in the path.Example: