[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

ruby under cygwin & windows paths

Mojca Miklavec

1/13/2006 12:12:00 PM

Hello,

I'm using a script located under
c:\mypath\myscript.rb
which has
require 'mylib'
(I have another file c:\mypath\mylib.rb.)

If I call ruby, the cygwin executable is called (I have no admin
rights on the computer, so I can't afford to install another native
windows version of ruby.)

Now the problem:
If I go to c:\mypath and call myscript from there, everything works OK.
File.dirname(__FILE__) is set to "/cygdrive/c/mypath" and properly
included in $LOAD_PATH.

But if I execute the script from somewhere else, inclusion doesn't
work any more:

C:/mypath/myscript.rb:10:in `require': No such file to load -- mylib (LoadError)
from C:/mypath/myscript.rb:10

since File.dirname(__FILE__) is now set to "c:\mypath" and this one
also gets included in $LOAD_PATH. But cygwin cannot access that path
by default.

After adding
$LOAD_PATH << '/cygdrive/c/mydir'
to the script it works again, but I may not afford to modify the
script by hardcoding the path into it since it has to work on other
computers as well.

Is there a way to modify the script (in a compatible way with the rest
of the world) or (preferrably) to change the settings in cygwin
somehow, so that the inclusion will work again without hardcoding the
path?

Any help would be appreciated,
Mojca Miklavec


15 Answers

David Vallner

1/13/2006 1:24:00 PM

0

On Fri, 13 Jan 2006 13:12:02 +0100, Mojca Miklavec
<mojca.miklavec.lists@gmail.com> wrote:

> Hello,
>
> I'm using a script located under
> c:\mypath\myscript.rb
> which has
> require 'mylib'
> (I have another file c:\mypath\mylib.rb.)
>
> If I call ruby, the cygwin executable is called (I have no admin
> rights on the computer, so I can't afford to install another native
> windows version of ruby.)
>
> Now the problem:
> If I go to c:\mypath and call myscript from there, everything works OK.
> File.dirname(__FILE__) is set to "/cygdrive/c/mypath" and properly
> included in $LOAD_PATH.
>
> But if I execute the script from somewhere else, inclusion doesn't
> work any more:
>
> C:/mypath/myscript.rb:10:in `require': No such file to load -- mylib
> (LoadError)
> from C:/mypath/myscript.rb:10
>
> since File.dirname(__FILE__) is now set to "c:\mypath" and this one
> also gets included in $LOAD_PATH. But cygwin cannot access that path
> by default.
>
> After adding
> $LOAD_PATH << '/cygdrive/c/mydir'
> to the script it works again, but I may not afford to modify the
> script by hardcoding the path into it since it has to work on other
> computers as well.
>
> Is there a way to modify the script (in a compatible way with the rest
> of the world) or (preferrably) to change the settings in cygwin
> somehow, so that the inclusion will work again without hardcoding the
> path?
>
> Any help would be appreciated,
> Mojca Miklavec
>


I'd guess thst's because the Cygwin ruby expects a POSIX path, not the
Windows one. The wonderful tool Cygwin is, it doesn't do miracles - you
should always use Cygwin tools from a Cygwin shell, not from CMD or by
putting them on the path by default. The first case works because for a
file in the current directory is the same as the Cygwin POSIX path.

If you can use bash, I'd say switch to using the Cygwin shell on that
machine.

David Vallner


Robert Klemme

1/13/2006 1:43:00 PM

0

Mojca Miklavec wrote:
> Hello,
>
> I'm using a script located under
> c:\mypath\myscript.rb
> which has
> require 'mylib'
> (I have another file c:\mypath\mylib.rb.)
>
> If I call ruby, the cygwin executable is called (I have no admin
> rights on the computer, so I can't afford to install another native
> windows version of ruby.)
>
> Now the problem:
> If I go to c:\mypath and call myscript from there, everything works
> OK. File.dirname(__FILE__) is set to "/cygdrive/c/mypath" and properly
> included in $LOAD_PATH.
>
> But if I execute the script from somewhere else, inclusion doesn't
> work any more:
>
> C:/mypath/myscript.rb:10:in `require': No such file to load -- mylib
> (LoadError) from C:/mypath/myscript.rb:10
>
> since File.dirname(__FILE__) is now set to "c:\mypath" and this one
> also gets included in $LOAD_PATH. But cygwin cannot access that path
> by default.
>
> After adding
> $LOAD_PATH << '/cygdrive/c/mydir'
> to the script it works again, but I may not afford to modify the
> script by hardcoding the path into it since it has to work on other
> computers as well.
>
> Is there a way to modify the script (in a compatible way with the rest
> of the world) or (preferrably) to change the settings in cygwin
> somehow, so that the inclusion will work again without hardcoding the
> path?

You just need to set the environment variable RUBYLIB appropriately.
Either Windows or Unix path convention will do. You can do that either ad
hoc in the shell from where you execute your script, put it in .bashrc in
your home ("cd" in bash) or modify your complete environment by going to
"My Computer" and then setting your env var there.

Kind regards

robert

David Vallner

1/13/2006 1:46:00 PM

0

On Fri, 13 Jan 2006 14:23:37 +0100, David Vallner <david@vallner.net>
wrote:

>
> If you can use bash, I'd say switch to using the Cygwin shell on that
> machine.
>
> David Vallner
>


Also, you might try yet another ugly hack. Put a file called "ruby.bat"
somewhere that's on your PATH before the Cygwin bin directory. Then have
that file call the Cygwin bash with a script that transforms the Windows
path into a POSIX one (I'm almost sure Cygwin comes with a tool for that)
and calls ruby that way. The disadvantage to this is that it' bound to
break command line switches sooner or later. I might get back to this a
while later today, these are replies in a hurry.

David Vallner


Mojca Miklavec

1/13/2006 5:07:00 PM

0

David Vallner wrote:

> Also, you might try yet another ugly hack. Put a file called "ruby.bat"
> somewhere that's on your PATH before the Cygwin bin directory. Then have
> that file call the Cygwin bash with a script that transforms the Windows
> path into a POSIX one (I'm almost sure Cygwin comes with a tool for that)
> and calls ruby that way. The disadvantage to this is that it' bound to
> break command line switches sooner or later. I might get back to this a
> while later today, these are replies in a hurry.

Thanks. I didn't think about creating another ruby.bat file. There's a
"cygpath" utility in cygwin, but I didn't figure out yet how to use it
to call another program an to tell him which paths to use.

I didn't write the scripts by myself. ConTeXt (a kind of TeX
extension/macro package) uses perl and ruby for different tasks, so
that ruby is called somewhere inbetween. I can't run the whole stuff
from bash since I don't have ConTeXt installed under cygwin, but
ruby.bat might help perhaps. It's pretty complicated situation (one
runs an exe which calls a ruby script which calls another perl script
which calls another ruby script, ...) I'll also try to find someone
who knows cygwin slightly better if everything else fails.

I didn't even notice that cygwin is (mis)used for ruby (most scripts
work properly) until I struggled against some problems.

Thanks a lot for help.

Mojca


Thomas

1/13/2006 5:51:00 PM

0

> Thanks. I didn't think about creating another ruby.bat file. There's a
> "cygpath" utility in cygwin, but I didn't figure out yet how to use it
> to call another program an to tell him which paths to use.

I think you can run ruby using something like

bash -c "ruby '$(cygpath -u %1)' %2 %3 %4 %5 %6 %7 %8 %9"

Maybe you could put this into some kind of ruby.bat. I don't know if
cmd.exe provided this kind of substitution which would make things easier.

> I don't have ConTeXt installed under cygwin

But which probably is the way to go here.

Even if you don't have administration rights, you should be able to
compile it from source & install it in your user dir. (Maybe, somehow.)

Cheers,
Thomas.






___________________________________________________________
Telefonate ohne weitere Kosten vom PC zum PC: http://messenge...


David Vallner

1/13/2006 7:39:00 PM

0

On Fri, 13 Jan 2006 18:50:59 +0100, Thomas <sanobast-2005a@yahoo.de> wrote:

>> Thanks. I didn't think about creating another ruby.bat file. There's a
>> "cygpath" utility in cygwin, but I didn't figure out yet how to use it
>> to call another program an to tell him which paths to use.
>
> I think you can run ruby using something like
>
> bash -c "ruby '$(cygpath -u %1)' %2 %3 %4 %5 %6 %7 %8 %9"
>
> Maybe you could put this into some kind of ruby.bat. I don't know if
> cmd.exe provided this kind of substitution which would make things
> easier.
>

There might be issues if ConTeXt is hardcoded ro run "ruby.exe", instead
of just "ruby" in a subshell. This is probably the first and last time I
see something that could be done with exec() instead of spawning a
subprocess...

The above command line should have "ruby.exe" instead of just ruby,
otherwise the BAT script would recurse forever. It seems you have the
Cygwin\bin on the path already, so that should be fine. Unfortunately,
despite the fact CMD came pretty close to a usable shell in XP, you still
have to do the batch argument hack there - it seems you can't specify "all
arguments after and including the second".

If by any chance the argument hack breaks ConTeXt, or that runs ruby with
some switches before the script filename, you can always have ruby.bat do
"ruby.js %*", and have the JScript play around with the arguments, like
finding the one that ends with ".rb" and then have cygpath have a go at
it. And afterwards, give your local admin a printout of this thread, and a
five dollar note saying "here, go buy a clue".

>> I don't have ConTeXt installed under cygwin
>
> But which probably is the way to go here.
>
> Even if you don't have administration rights, you should be able to
> compile it from source & install it in your user dir. (Maybe, somehow.)
>
>

It should be doable. Configure it with "./configure --prefix='~'" and it
should work. You might want to modify .profile to put ~/bin at the start
of PATH. And you also have to tell the linker where to find ~/lib, but
someone else will have to elucidate on that, I'm not very (at all)
experienced in ways *nixy that involve playing with the dynamic linking.

David Vallner


Robert Klemme

1/13/2006 11:24:00 PM

0

Interestingly enough my news posting didn't make it to the mail side
http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/50b3c1...

I still think modifying the environment is a better approach than
writing wrapper scripts.

cheers

robert


2006/1/13, Mojca Miklavec <mojca.miklavec.lists@gmail.com>:
> Hello,
>
> I'm using a script located under
> c:\mypath\myscript.rb
> which has
> require 'mylib'
> (I have another file c:\mypath\mylib.rb.)
>
> If I call ruby, the cygwin executable is called (I have no admin
> rights on the computer, so I can't afford to install another native
> windows version of ruby.)
>
> Now the problem:
> If I go to c:\mypath and call myscript from there, everything works OK.
> File.dirname(__FILE__) is set to "/cygdrive/c/mypath" and properly
> included in $LOAD_PATH.
>
> But if I execute the script from somewhere else, inclusion doesn't
> work any more:
>
> C:/mypath/myscript.rb:10:in `require': No such file to load -- mylib (LoadError)
> from C:/mypath/myscript.rb:10
>
> since File.dirname(__FILE__) is now set to "c:\mypath" and this one
> also gets included in $LOAD_PATH. But cygwin cannot access that path
> by default.
>
> After adding
> $LOAD_PATH << '/cygdrive/c/mydir'
> to the script it works again, but I may not afford to modify the
> script by hardcoding the path into it since it has to work on other
> computers as well.
>
> Is there a way to modify the script (in a compatible way with the rest
> of the world) or (preferrably) to change the settings in cygwin
> somehow, so that the inclusion will work again without hardcoding the
> path?
>
> Any help would be appreciated,
> Mojca Miklavec
>
>


David Vallner

1/14/2006 12:50:00 AM

0

On Sat, 14 Jan 2006 00:23:51 +0100, Robert Klemme
<shortcutter@googlemail.com> wrote:

> Interestingly enough my news posting didn't make it to the mail side
> http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/50b3c1...
>
> I still think modifying the environment is a better approach than
> writing wrapper scripts.
>
> cheers
>
> robert
>
>

If it does indeed work (Which I can't, or rather won't test), it
indubitably is. Wrapper scripts are just a hack that first came to mind
since I use them for a few other things - notably automagically running ri
in glorious ANSI technicolour and paging it via less, and basically
emulating alias on CMD.

The global environment change has a pitfall if RUBYLIB happens to be set
systemwide, but that shouldn't be the case, and even if so, I think
user-set PATH-like environment variables always come first in the final
value.

David Vallner


Robert Klemme

1/14/2006 10:02:00 AM

0

2006/1/14, David Vallner <david@vallner.net>:
> If it does indeed work (Which I can't, or rather won't test), it
> indubitably is. Wrapper scripts are just a hack that first came to mind
> since I use them for a few other things - notably automagically running ri
> in glorious ANSI technicolour and paging it via less, and basically
> emulating alias on CMD.

The nice thing about modifying the env is that you can create a
default location for your self written lib scripts that and you can
always access them without additional hassle. Wrapper scripts are
just plan ugly IMHO.

> The global environment change has a pitfall if RUBYLIB happens to be set
> systemwide, but that shouldn't be the case, and even if so, I think
> user-set PATH-like environment variables always come first in the final
> value.

I would only set it globally if the libs are intended to be used by
all users. About precedence: user settings always override global
settings but you can also use the global setting to define a user
variable, e.g. PATH=%PATH%;M:\y\local\path

Kind regards

robert


Nobuyoshi Nakada

1/14/2006 3:37:00 PM

0

Hi,

At Fri, 13 Jan 2006 21:12:02 +0900,
Mojca Miklavec wrote in [ruby-talk:175655]:
> But if I execute the script from somewhere else, inclusion doesn't
> work any more:
>
> C:/mypath/myscript.rb:10:in `require': No such file to load -- mylib (LoadError)
> from C:/mypath/myscript.rb:10
>
> since File.dirname(__FILE__) is now set to "c:\mypath" and this one
> also gets included in $LOAD_PATH. But cygwin cannot access that path
> by default.

Sounds strange. File.dirname("C:/mypath/myscript.rb") is
"c:\mypath" but not "c:/mypath"? How do you add it to
$LOAD_PATH?

--
Nobu Nakada