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

267
Vistas
Get nginx version in Ruby

I'm trying to obtain the current version of nginx in Ruby. I've tried all of these, and nothing seems to work:

a = `nginx -v`
puts a             # ==> nil
a = `nginx -V`
puts a             # ==> nil again
a = system('nginx -v')
puts a             # ==> nil

Anybody know how I can obtain this data? Strange behaviour. Same for postgres and ruby work fine.

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

0

There are a handful of methods that can run system commands and all of them are working differently. For example `date` works different than system('date'). More here.

Also, some commands write to STDOUT, some to STDERR and, apparently nginx -v writes to STDERR. For this scenario there's another option which gives access to more info: Open3

require 'open3'
stdout, stderr, status = Open3.capture3("nginx -v")
# ["", "nginx version: nginx/1.21.6\n", #<Process::Status: pid 22253 exit 0>] 

stdout, stderr, status = Open3.capture3("date")
# ["Sun Jan 30 12:55:29 EET 2022\n", "", #<Process::Status: pid 22264 exit 0>]

stdout, stderr, status = Open3.capture3("ruby -v")
["ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [arm64-darwin21]\n", "", #<Process::Status: pid 22571 exit 0>]
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