tags:

views:

472

answers:

2

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.

UPDATE: The Rake source code does it like this:

  RUBY = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']).
    sub(/.*\s.*/m, '"\&"')

But I'll leave this question open in case anyone has an alternative version.

+2  A: 

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

VitalieL
+1  A: 

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

rogerdpack