将java -version重定向到文件或变量 [英] Redirect java -version to file or variable
问题描述
也许这是一个愚蠢的问题,但我试图将java -version命令的退出重定向到一个文件或变量,但它不工作。
Server = Linux CentOS 6
我的shell脚本代码
java -version>> test.txt
同时我试图将它分配给一个变量:
JAVA_CHECK =`java -version`
$ b b
即使从命令行运行这些命令仍然不工作。
当我说它不工作,我的意思是命令的退出显示
java -version
写入stderr(fileno 2),而不是stdout(fileno 1)。您可以将stderr重定向到一个文件:
java -version 2& test.txt
#cat test.txt
#java版本1.7.0_25
#OpenJDK运行时环境
#[...]
或者,您可以将stderr重定向到stdout:
JAVA_CHECK =`java -version 2>& 1`
#echo $ JAVA_CHECK
#java版本1.7.0_25OpenJDK运行时环境[...]
Maybe it is a silly question, but I'm trying to redirect the exit of "java -version" command to a file or variable but it doesn't work.
Server = Linux CentOS 6
My code in shell script
java -version >> test.txt
Also I'm trying to assign it to a variable:
JAVA_CHECK=`java -version`
Even running those command from command-line it still not working.
when I say it doesnt work, I mean that the exit of the command is being showed in my screen instead to redirect it to a file or wherever
...
java -version
writes to stderr (fileno 2), not stdout (fileno 1). You can redirect stderr to a file:
java -version 2> test.txt
# cat test.txt
# java version "1.7.0_25"
# OpenJDK Runtime Environment
# [...]
Or you can redirect stderr to stdout:
JAVA_CHECK=`java -version 2>&1`
# echo $JAVA_CHECK
# java version "1.7.0_25" OpenJDK Runtime Environment [...]
这篇关于将java -version重定向到文件或变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!