Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I reliably discover the full path of the Ruby executable?

Tags:

scripting

ruby

I want to write a script, to be packaged into a gem, which will modify its parameters and then exec a new ruby process with the modified params. In other words, something similar to a shell script which modifies its params and then does an exec $SHELL $*. In order to do this, I need a robust way of discovering the path of the ruby executable which is executing the current script. I also need to get the full parameters passed to the current process - both the Ruby parameters and the script arguments.

like image 496
Avdi Avatar asked Oct 17 '08 18:10

Avdi


2 Answers

The Rake source code does it like this:

  RUBY = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']).
    sub(/.*\s.*/m, '"\&"')
like image 93
Avdi Avatar answered Sep 27 '22 20:09

Avdi


If you want to check on linux: read files:

  • /proc/PID/exe
  • /proc/PID/cmdline

Other useful info can be found in /proc/PID dir

like image 24
Vitalie Avatar answered Sep 27 '22 18:09

Vitalie