batch-filesilentoutput-redirect

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


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?


Solution

  • Try adding 2> in command

    java -version 2> nul