Ad
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.
Ad
Answer
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>]
Ad
source: stackoverflow.com
Related Questions
- → Trigger a click with jQuery using link_to of rails 4
- → Adding html data attribute to simple_forms input
- → How to remove parameters from the root URL if it does I18n
- → passing parameters to rails back end from an ajax call
- → Blocking ?page= in robots.txt
- → react js and rails Updating state on a component with active record relationship
- → Kaminari How to process routes as javascript
- → State not passed into prop
- → Cannot read property 'modalIsOpen' of undefined
- → Objects not valid issue
- → How can I add a featured image from a blog post to my homepage on shopify
- → Need "add to cart" button price to update with correct amount depending on what checkbox is checked
- → GET /admin/webhooks.json returns an empty array
Ad