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.
我想写一个脚本,打包成一个gem,它将修改它的参数,然后用修改后的参数执行一个新的ruby过程。换句话说,类似于修改其params然后执行exec $ SHELL $ *的shell脚本。为了做到这一点,我需要一种健壮的方法来发现执行当前脚本的ruby可执行文件的路径。我还需要获取传递给当前进程的完整参数 - Ruby参数和脚本参数。
3 个解决方案
#1
6
The Rake source code does it like this:
Rake源代码是这样的:
RUBY = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']).
sub(/.*\s.*/m, '"\&"')
#2
4
If you want to check on linux: read files:
如果你想检查linux:读取文件:
- /proc/PID/exe
- /proc/PID/cmdline
Other useful info can be found in /proc/PID dir
其他有用的信息可以在/ proc / PID目录中找到
#3
0
For the script parameters, of course, use ARGV
.
当然,对于脚本参数,请使用ARGV。
#1
6
The Rake source code does it like this:
Rake源代码是这样的:
RUBY = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']).
sub(/.*\s.*/m, '"\&"')
#2
4
If you want to check on linux: read files:
如果你想检查linux:读取文件:
- /proc/PID/exe
- /proc/PID/cmdline
Other useful info can be found in /proc/PID dir
其他有用的信息可以在/ proc / PID目录中找到
#3
0
For the script parameters, of course, use ARGV
.
当然,对于脚本参数,请使用ARGV。