Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

148
Vistas
Redirect java -version to file or variable

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

...

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

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 [...]
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda