0

I am trying to run a small batch file with the following lines to print the output of java version.

@echo off
set instDir=%cd%
set JAVA_DIR="%instDir%\bin\jre\bin\java.exe"
%JAVA_DIR% -version > output.txt

When I run (double click) this file with "*.bat" extension, nothing is written to the output.txt.

When I execute the same file from command prompt, it prints the version on command prompt, but does not print to the file.

gthm
  • 1,878
  • 4
  • 26
  • 37
  • Got the link to answer Sorry. http://stackoverflow.com/questions/5980767/command-line-output-to-a-txt-file-java-exe-version-returning-blank – gthm Nov 29 '12 at 07:03

1 Answers1

0

You are trying to redirect the standard output but you need to redirect the error output:

@echo off
set instDir=%cd%
set JAVA_DIR="%instDir%\bin\jre\bin\java.exe"
%JAVA_DIR% -version 2> ".\output.txt"
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417