The original question is quite interesting. Offhand I don’t see a way
to do it. Even using something like sys-proctable wouldn’t guarantee
an accurate result. On certain Unix-style OS flavors, one might be
able to launch an external command and parse the results (i.e. using lsof) to learn more.
Good question! If you or someone else comes up with a good idea, I
look forward to seeing it here.
Aaron out.
(OT comment: It’s easy to get frustrated on both sides of discussions,
as asker when many people wanting to be helpful ask “why” or “for what
purpose” when sometimes the asker may not want to share why or
purpose–or the purpose may simply be “because it’s a fascinating
question that has piqued my curiosity”–and as a helpful answerer,
when one doesn’t know exactly what the asker wants, trying to get more
useful information can easily lead to frustration. So for me in
either role, if I find myself getting snippy, it’s time for me to back
away, take a break or a deep breath, and just be grateful that there
are other geeks like me out there who share similar interests.)
Moving ruby from where it was installed is not a good idea. It expects to
be run from where make install put it, not from any other location.
Of course, this doesn’t mean that people won’t do that, although I’m
having
trouble thinking of a case where it would matter. FWIW, the rake example
gives me the same string if I mv $(which ruby) instead of cp’ing it, so
I
assume most of the “give me the ruby binary path” things are just going
to
be reading build info.
On Thu, Sep 15, 2011 at 12:09 AM, Michal S. [email protected]
wrote:
I don’t care where it is installed, I care where it is.
Those are synonyms, since the user can execute Ruby programs. How
the user does that is simply none of your concern, but the user’s
problem (i.e. whether it’s a copied instance of Ruby, or a full system
installation, or an RVM managed Ruby, or a script executed against all
the Rubies pik knows about are all valid and common ways to run Ruby
scripts).
check that the function works as I want.
It would be much easier if I could just run Ruby and pass it a test
program as argument.
And
$ #{Gem.ruby} /path/to/testscript
doesn’t suffice?
Makes me wonder about what you’ve written, to be honest.
On the other hand, OS X can run Ruby, has exec() and has linker
support for moving whole applications with libraries and all. I am not
sure how much Ruby would break by installing in this fashion, though.
Reading between the lines, it sounds like Michal has an application,
including the Ruby interpreter, distributed on CD, and the users of this
application (who might not want or be able to rely on the system ruby)
want to copy it off onto their hard drives and run it from there.
Is that right?
Going back to the first email:
It would be quite helpful to re-execute the interpreter when running
tests sometimes.
On the rare occasions where this has made sense in the past, I’ve lashed
something together with exec "#{$0} ..." and detected either arguments
or environment variables.
However, I suspect that there is an easier way to get the same results
in this case
I don’t care where it is installed, I care where it is.
The reason is quite simple and i said it in the first mail. I was
trying to write a test for a function that redirects STDERR.
Now I have a library of functions already tested that redirects
everything but it runs a command with STD I/O/E redirected, not ruby.
AFAICT it is not possible to pass a “-” into exec to have ruby
re-executed, and exec is what I use.
So to write the test I have to use fork and do manual redirections to
check that the function works as I want.
It would be much easier if I could just run Ruby and pass it a test
program as argument.
Now I am running this on Linux so there is not much point in moving
the Ruby interpreter. There are often symlinks but the path under
which Ruby was originally installed would usually work, and I don’t
run the test during Ruby installation.
Also exec is not portable to Windows so I need not worry about that.
On the other hand, OS X can run Ruby, has exec() and has linker
support for moving whole applications with libraries and all. I am not
sure how much Ruby would break by installing in this fashion, though.
So maybe I was looking for solution needlessly general because I did
not consider the consequences of config not being enough. I guess
there are other things that would break if it weren’t.
There were people trying to install their Ruby application from a CD
and for those config would not be enough but $0 and knowledge of their
CD layout should suffice.
Reading between the lines, it sounds like Michal has an application,
including the Ruby interpreter, distributed on CD, and the users of this
application (who might not want or be able to rely on the system ruby)
want to copy it off onto their hard drives and run it from there.
Is that right?
In that case, I’d distribute Ruby as an installer package for the
distributions I want to support:
The Windows RubyInstaller
.deb packages for Debian and derivatives
.rpm packages for Fedora, OpenSUSE, and derivatives (RHEL,
SLED/SLES, and CentOS/SL as RHEL derivatives)
Include the source for Ruby (GPL mandates access to the sources
anyway, if binaries are distribute, so might as well fill up the CD)
Instructions to build from source, if no binary package is distributed
Let the users worry about how their systems are managed. That’s why
package management/installers exist, after all!
check that the function works as I want.
Makes me wonder about what you’ve written, to be honest.
So long as I always use gems, sure.
It’s probably the user’s problem if they delete the Ruby interpreter
in the location where it was initially installed.
While it’s totally possible to move the interpreter and still run it
many other things would likely break.
On the other hand, OS X can run Ruby, has exec() and has linker
support for moving whole applications with libraries and all. I am not
sure how much Ruby would break by installing in this fashion, though.
That’s Apple’s problem, not yours.
That’s true so long as I don’t try to run anything on such Ruby
installation.
Also Apple sidestepped this by including Ruby in the system core where
it is always installed in /usr.
But since Ruby works on Windows it should work as a standalone
application on OS X too.
First off, I’m very new to Ruby and I’m trying to wrap my head around a
few things, so if this sounds simplistic I apologize in advance I did do
some searching but I’m not sure how to fix this error.
I’m using Mac OS X (Lion) and I’ve started a script that reads in an xml
file (ditamap) and parses the data, so I only end up with a listing of
files that map uses.
When I run the script using Ruby 1.8.x, the script works as I expected
it to work. However, when I run it using Ruby 1.9.x, I get the
following error:
`gsub’: invalid byte sequence in US-ASCII (ArgumentError)
From what I’ve determined via the web, this has to do with some
mis-match of what the OS is using vs. what Ruby is using. One post I
read recommended reading the file as a binary to get around this.
However, I’m wondering what the real fix is for this problem, and why is
it happening in 1.9 vs. 1.8.