sh7411usa
sh7411usa

Reputation: 315

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?

Upvotes: 0

Views: 1012

Answers (1)

Sayed Hussain Mehdi
Sayed Hussain Mehdi

Reputation: 151

Try adding 2> in command

java -version 2> nul

Upvotes: 1

Related Questions