I'm writing code to use Win32 API to detect a java's version. E.g.
Basically, I'm following MSDN Creating a Child Process with Redirected Input and Output https://msdn.microsoft.com/en-us/library/ms682499%28VS.85%29.aspx
string GetJavaVersion(string sJavaExePath) {
}
This is the pseudo client code:
ASSERT(GetJavaVersion("C:\Program Files (x86)\Java\jdk1.7.0_17\bin\java.exe") == "1.7.0_25");
I can get the result as:
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
Java HotSpot(TM) Client VM (build 23.25-b01, mixed mode, sharing)
However, the result is sent back from stdErr, while I though it should return from stdOut.
Does it make sense to receive the string from stdErr?
The answer is stderr. We can redirect stderr and stdout seperately and see,
$ java -version 2>stderr.txt 1>stdout.txt
$ cat stderr.txt
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)
You can also redirect stderr to stdout,
$ java -version 2>&1
which would allow you to read it from stdout.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With