How can I find the name of the current ruby interpreter? It’s not $0,
since that’s the main ruby script. I want to be able to start another
process using the same interpreter, whatever that happens to be.
— Joel VanderWerf vjoel@PATH.Berkeley.EDU wrote: >
How can I find the name of the current ruby interpreter? It’s not $0,
since that’s the main ruby script. I want to be able to start another
process using the same interpreter, whatever that happens to be.
exec $(which ruby) name_of_script.rb
– Thomas Adam
···
=====
“The Linux Weekend Mechanic” – http://linuxgazette.net
“TAG Editor” – http://linuxgazette.net
“ We’ll just save up your sins, Thomas, and punish
you for all of them at once when you get better. The
experience will probably kill you. :)”
– Benjamin A. Okopnik (Linux Gazette Technical Editor)
Yahoo! Messenger - Communicate instantly…“Ping”
your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html
require ‘rbconfig’
ruby = Config::CONFIG.fetch('bindir') + "/" +
Config::CONFIG.fetch('RUBY_INSTALL_NAME')
ruby = Config.expand(ruby)
exec ruby, "-e", 'puts VERSION'
AFAIK, “/” works in win32. HTH,
···
On Tue, 6 Jan 2004 06:09:47 +0900 Joel VanderWerf vjoel@PATH.Berkeley.EDU wrote:
How can I find the name of the current ruby interpreter? It’s not $0,
since that’s the main ruby script. I want to be able to start another
process using the same interpreter, whatever that happens to be.
–
Ryan Pavlik rpav@mephle.com
“Oh for the love of evil, not this again.” - 8BT
Thomas Adam wrote:
— Joel VanderWerf vjoel@PATH.Berkeley.EDU wrote: >
How can I find the name of the current ruby interpreter? It’s not $0,
since that’s the main ruby script. I want to be able to start another
process using the same interpreter, whatever that happens to be.exec $(which ruby) name_of_script.rb
I should have been clearer:
-
It has to work on windows, too.
-
It has to work correctly even if you originally invoked a ruby
interpreter that is not on your PATH or is not the first one on your PATH.
Ryan Pavlik wrote:
How can I find the name of the current ruby interpreter? It’s not $0,
since that’s the main ruby script. I want to be able to start another
process using the same interpreter, whatever that happens to be.require 'rbconfig' ruby = Config::CONFIG.fetch('bindir') + "/" + Config::CONFIG.fetch('RUBY_INSTALL_NAME') ruby = Config.expand(ruby) exec ruby, "-e", 'puts VERSION'
Almost there. It won’t work if you’ve got 1.8.0 and 1.8.1 both installed
(if you installed 1.8.1 later, requiring ‘rbconfig’ generates an error).
And it doesn’t detect that you started ruby with an alias (‘alias
rv=ruby -v)’, but it’s good enough for my purposes. What I was looking
for was a way to see the original command line. On linux I could use the
proc file system, but that’s just linux…
Thanks!
AFAIK, “/” works in win32. HTH,
It does, though I tend to use File.join for clarity.
···
On Tue, 6 Jan 2004 06:09:47 +0900 > Joel VanderWerf vjoel@PATH.Berkeley.EDU wrote:
Ryan Pavlik wrote:
require 'rbconfig' ruby = Config::CONFIG.fetch('bindir') + "/" + Config::CONFIG.fetch('RUBY_INSTALL_NAME') ruby = Config.expand(ruby) exec ruby, "-e", 'puts VERSION'
Almost there. It won’t work if you’ve got 1.8.0 and 1.8.1 both
installed (if you installed 1.8.1 later, requiring ‘rbconfig’
generates an error).
Maybe installing one over the other… that’s not a good thing. I
suggest using Encap. But it works fine with 1.8.1 here.
And it doesn’t detect that you started ruby with an alias (‘alias
rv=ruby -v)’, but it’s good enough for my purposes.
That, of course, is impossible.
What I was looking for was a way to see the original command
line. On linux I could use the proc file system, but that’s just
linux…
Oh, well, you should have said that right off. That’s not generally
possible. Certainly, there’s no (portable) way to get the invocation
from the shell or otherwise. Even if you could, aliases are expanded
before the shell executes the command, so you couldn’t get that,
either.
···
On Tue, 6 Jan 2004 07:20:08 +0900 Joel VanderWerf vjoel@PATH.Berkeley.EDU wrote:
–
Ryan Pavlik rpav@mephle.com
“Oh for the love of evil, not this again.” - 8BT
Ryan Pavlik wrote:
···
On Tue, 6 Jan 2004 07:20:08 +0900 > Joel VanderWerf vjoel@PATH.Berkeley.EDU wrote:
Ryan Pavlik wrote:
require ‘rbconfig’
ruby = Config::CONFIG.fetch(‘bindir’) + “/” +
Config::CONFIG.fetch(‘RUBY_INSTALL_NAME’)
ruby = Config.expand(ruby)exec ruby, “-e”, ‘puts VERSION’
Almost there. It won’t work if you’ve got 1.8.0 and 1.8.1 both
installed (if you installed 1.8.1 later, requiring ‘rbconfig’
generates an error).Maybe installing one over the other… that’s not a good thing. I
suggest using Encap.But it works fine with 1.8.1 here.
Good idea…I’ve been meaning to lear encap or stow. But your suggestion
works with 1.8.1 here, also (I guess since that’s the last installed
version), so I’m happy.