java -version correctly prints Java version. java -version >> test.txt creates an empty file. My problem is that WScript.Shell has exactly the same behavior (empty string returned). Why does this happen, and how to get things right?

java -version displays the version information on standard error rather than standard output... so you need to redirect that:
java -version 2>> test.txt
Here the 2>> means "redirect standard error, appending it to the given file".
See more on this question at Stackoverflow