It's not clear to me how "puts" works in Ruby for the output of a command that throws its output to stderr.
Look at this code:
command="/usr/bin/java -version"
result=`#{command}`
puts result
puts "XX#{result}XX"
The result is:
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
XXXX
java -version sends its output to stderr (I am aware that in order to prevent this I should have used 2>&1 at the end of the command)
My question: The variable "result" in reality is empty, but the first puts prints the stderr output and the second puts the stdout (which is empty). Why? What's going on?