How to solve the problem that java version is stderr output
This article focuses on "java version for stderr output how to solve", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to solve the problem of java version for stderr output.
Phenomenon
Today, write an initialization server script, want to get the java version, the result using java-version has been unable to use sed and awk processing, after experiments, found that
The java-version output is stderr and cannot be processed.
Test # output command 2 stderr and 1 stdout to the specified file to view the contents of the file Verify that the java-version output is stderr [root@template yum.repos.d] # java-version 2 > / tmp/java_version_stderr.out 1 > / tmp/java_ stdout.out [root @ template yum.repos.d] # cat / tmp/java_version_stderr.out openjdk version "1.8.0x181" OpenJDK Runtime Environment (build 1.8.0_181-b13) OpenJDK 64-Bit Server VM (build 25.181-b13) Mixed mode) [root@template yum.repos.d] # cat / tmp/java_stdout.out # you can see the java-version output as stderr So if we want to continue processing java-version output, we need to redirect to stdout solution java_ver= `java-version 2 > & 1 | sed '1javd' | sed's / "/ / g' | awk' {print $NF}'| awk-filler.'{print $1 $2}''so far, I believe you have a better understanding of" java version for stderr output ", you might as well do it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!