Why is cmd output not redirecting to nul in batch file?

830 Views Asked by At

Am writing a batch script to detect if java is installed globally on a pc. am using:

java -version>nul
if not %errorlevel%==0 ( echo script requires java)

Also tried using cmd /c java -version>nul.

Script works fine, but console is outputting the java version when java is present and

'java' is not recognized as an internal or external command, operable program or batch file.

when java is not present. I am trying to quash this output, and do detection silently. what am i doing wrong?

1

There are 1 best solutions below

1
Sayed Hussain Mehdi On BEST ANSWER

Try adding 2> in command

java -version 2> nul