librelist archives

« back to archive

Dumb ruby question

Dumb ruby question

From:
Cecil Coupe
Date:
2012-02-01 @ 08:05
In my effort to cross compile Shoes from Linux to mingw I have to know
the path to the Ruby that is running (as opposed to the ruby I'm
compiling for. 

ccoupe@twb:~/Projects/shoes$ which ruby
/home/ccoupe/.rvm/rubies/ruby-1.9.2-p0/bin/ruby

That is the value I want to get from a running script through some ENV[]
or $constant machinations. I can't use rbconfig.rb because that is set to 
the target
mingw environment's.  Yes, I could shell out to get the 'which' value but 
that is so fragile.

Anybody know how to get the invoking ruby's path from inside a script?

Re: [shoes] Dumb ruby question

From:
Eric Watson
Date:
2012-02-01 @ 12:55
Cecil,

What about setting the env variable yourself? Slightly less fragile
than `which`?

There's the RUBYPATH env var that is (sort of) meant for this kind of
thing, especially if you can control your ruby invocation with the -S
switch.

http://ruby-doc.org/docs/ProgrammingRuby/html/rubyworld.html

On Feb 1, 2012, at 2:06 AM, Cecil Coupe <ccoupe@cableone.net> wrote:

> In my effort to cross compile Shoes from Linux to mingw I have to know
> the path to the Ruby that is running (as opposed to the ruby I'm
> compiling for.
>
> ccoupe@twb:~/Projects/shoes$ which ruby
> /home/ccoupe/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
>
> That is the value I want to get from a running script through some ENV[]
> or $constant machinations. I can't use rbconfig.rb because that is set 
to the target
> mingw environment's.  Yes, I could shell out to get the 'which' value 
but that is so fragile.
>
> Anybody know how to get the invoking ruby's path from inside a script?
>

Re: [shoes] Dumb ruby question

From:
J. Kaiden
Date:
2012-02-01 @ 10:52
hi Cecil -

  This should work:

puts ENV['PATH']

  Good luck,

  - j

On Wed, Feb 1, 2012 at 8:05 AM, Cecil Coupe <ccoupe@cableone.net> wrote:

> In my effort to cross compile Shoes from Linux to mingw I have to know
> the path to the Ruby that is running (as opposed to the ruby I'm
> compiling for.
>
> ccoupe@twb:~/Projects/shoes$ which ruby
> /home/ccoupe/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
>
> That is the value I want to get from a running script through some ENV[]
> or $constant machinations. I can't use rbconfig.rb because that is set to
> the target
> mingw environment's.  Yes, I could shell out to get the 'which' value but
> that is so fragile.
>
> Anybody know how to get the invoking ruby's path from inside a script?
>
>

Re: [shoes] Dumb ruby question

From:
Cecil Coupe
Date:
2012-02-02 @ 08:25
Thanks for the replies.

ENV['PATH'] is a string of : separated paths that has to be parsed
looking for bin/ruby inside. I own a hard copy book (gasp, the horror!)
of Programming Ruby, The Pragmatic Programmers Guide that Eric linked
to.  For MY purposes `which ruby`.chomp is actually not as fragile as I
thought. It also works so there is something to be said for that
utility. 

Anybody that stumbles upon my cross compile script in a build system
without 'which', they have more pressing issues to solve. 

--Cecil

On Wed, 2012-02-01 at 10:52 +0000, J. Kaiden wrote:
> hi Cecil -
> 
> 
>   This should work:
> 
> 
> puts ENV['PATH']
> 
> 
>   Good luck,
> 
> 
>   - j
> 
> On Wed, Feb 1, 2012 at 8:05 AM, Cecil Coupe <ccoupe@cableone.net>
> wrote:
>         In my effort to cross compile Shoes from Linux to mingw I have
>         to know
>         the path to the Ruby that is running (as opposed to the ruby
>         I'm
>         compiling for.
>         
>         ccoupe@twb:~/Projects/shoes$ which ruby
>         /home/ccoupe/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
>         
>         That is the value I want to get from a running script through
>         some ENV[]
>         or $constant machinations. I can't use rbconfig.rb because
>         that is set to the target
>         mingw environment's.  Yes, I could shell out to get the
>         'which' value but that is so fragile.
>         
>         Anybody know how to get the invoking ruby's path from inside a
>         script?
>         
> 
> 

Re: [shoes] Dumb ruby question

From:
Peter Fitzgibbons
Date:
2012-02-02 @ 11:56
Windows may or may not, depending upon mingw or cygwin

And, `which` is possibly going to miss direct-path execution of a specific
ruby.  That's a possibility with Linux on RVM or RbEnv

I found this
http://munkymorgy.blogspot.com/2009/04/ruby-shoes-get-full-path-of-current.html
Which funny enough is specifically about Shoooes!

Shoes On

Peter Fitzgibbons
(847) 859-9550
Email: peter.fitzgibbons@gmail.com
IM GTalk: peter.fitzgibbons
IM AOL: peter.fitzgibbons@gmail.com

Re: [shoes] Dumb ruby question

From:
Cecil Coupe
Date:
2012-02-03 @ 03:23
On Thu, 2012-02-02 at 05:56 -0600, Peter Fitzgibbons wrote:
> Windows may or may not, depending upon mingw or cygwin
> 
> And, `which` is possibly going to miss direct-path execution of a
> specific ruby.  That's a possibility with Linux on RVM or RbEnv

Yes all of that could happen but I've got an extremely limited
situation: Cywgin or Mingw users won't be running the Cross compile
scripts. So only Linux or OSX users need to deal with it.  The
extconf.rb is run from rakefiles using whatever ruby is current 

mkmf.rb is called from the extconf.rb and has it has no idea that anyone
would dare to create MingW gems or extensions from Linux.  Shoe's
rakefiles also depend on both build and target are the same
RUBY_PLATFORM. That's a bug report for another day.

> 
> I found this
> http://munkymorgy.blogspot.com/2009/04/ruby-shoes-get-full-path-of-current.html
> Which funny enough is specifically about Shoooes!
> 
> Shoes On
> 
> Peter Fitzgibbons
> (847) 859-9550
> Email: peter.fitzgibbons@gmail.com
> IM GTalk: peter.fitzgibbons
> IM AOL: peter.fitzgibbons@gmail.com
>