Reputation: 27
java -version
output like this:
> java -version
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
then I run grep
command, but can't get my expected result.
>java -version | grep "version"
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
My expected result is just only the first line
java version "1.8.0_101"
why ?
Upvotes: 0
Views: 31
Reputation: 195229
java -version
prints text to standard err, instead of standard output. so you should do:
java -version 2>&1|grep "version"
Upvotes: 1