Take the 2-minute tour ×

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.

share|improve this question
Don't update your question with an answer inline, just add an answer to your own question. That way people can upvote your answer. –  Mike Deck Oct 17 '08 at 20:22
note that you may also need require 'rbconfig' –  Bryan Larsen Nov 26 '09 at 21:35
add comment

3 Answers

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

share|improve this answer
add comment
up vote 4 down vote accepted

The Rake source code does it like this:

    sub(/.*\s.*/m, '"\&"')
share|improve this answer
add comment

for the script parameters, of course, use ARGV :) -r

share|improve this answer
add comment

Your Answer


