# Ruby under cygwin & windows paths

**URL:** <https://rubytalk.org/t/ruby-under-cygwin-windows-paths/24084>\
**Category:** ruby-talk\
**Created:** [13 January 2006 12:12 UTC](https://rubytalk.org/t/ruby-under-cygwin-windows-paths/24084 "2006-01-13T12:12:02Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mojca\_Miklavec](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@Mojca\_Miklavec](https://rubytalk.org/u/Mojca_Miklavec)\
**Post date:** [13 January 2006 12:12 UTC](https://rubytalk.org/t/ruby-under-cygwin-windows-paths/24084/1 "2006-01-13T12:12:02Z")

</div>

Hello,

I'm using a script located under  
&nbsp;&nbsp;&nbsp;&nbsp;c:\mypath\myscript.rb  
which has  
&nbsp;&nbsp;&nbsp;&nbsp;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)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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  
&nbsp;&nbsp;&nbsp;&nbsp;$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,  
&nbsp;&nbsp;&nbsp;&nbsp;Mojca Miklavec

---

<div class="post-metadata">

**Author:** ![David\_Vallner](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@David\_Vallner](https://rubytalk.org/u/David_Vallner)\
**Post date:** [13 January 2006 13:23 UTC](https://rubytalk.org/t/ruby-under-cygwin-windows-paths/24084/2 "2006-01-13T13:23:37Z")

</div>

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

> **···**
>
> 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  
> > &nbsp;&nbsp;&nbsp;&nbsp;c:\mypath\myscript.rb  
> > which has  
> > &nbsp;&nbsp;&nbsp;&nbsp;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)  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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  
> > &nbsp;&nbsp;&nbsp;&nbsp;$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,  
> > &nbsp;&nbsp;&nbsp;&nbsp;Mojca Miklavec

---

<div class="post-metadata">

**Author:** ![Robert\_K1](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/robert_k1/32/1830_2.png) [@Robert\_K1](https://rubytalk.org/u/Robert_K1)\
**Post date:** [13 January 2006 23:23 UTC](https://rubytalk.org/t/ruby-under-cygwin-windows-paths/24084/3 "2006-01-13T23:23:51Z")

</div>

Interestingly enough my news posting didn't make it to the mail side  
[http://groups.google.com/group/comp.lang.ruby/browse\_thread/thread/50b3c1b275cd0c6d](http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/50b3c1b275cd0c6d)

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  
> > &nbsp;&nbsp;&nbsp;&nbsp;c:\mypath\myscript.rb  
> > which has  
> > &nbsp;&nbsp;&nbsp;&nbsp;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)  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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  
> > &nbsp;&nbsp;&nbsp;&nbsp;$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,  
> > &nbsp;&nbsp;&nbsp;&nbsp;Mojca Miklavec

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada1](https://avatars.discourse-cdn.com/v4/letter/n/9f8e36/32.png) [@Nobuyoshi\_Nakada1](https://rubytalk.org/u/Nobuyoshi_Nakada1)\
**Post date:** [14 January 2006 15:37 UTC](https://rubytalk.org/t/ruby-under-cygwin-windows-paths/24084/4 "2006-01-14T15:37:27Z")

</div>

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)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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

---

<div class="post-metadata">

**Author:** ![David\_Vallner](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@David\_Vallner](https://rubytalk.org/u/David_Vallner)\
**Post date:** [13 January 2006 13:45 UTC](https://rubytalk.org/t/ruby-under-cygwin-windows-paths/24084/5 "2006-01-13T13:45:46Z")

</div>

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

> **···**
>
> 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

---

<div class="post-metadata">

**Author:** ![David\_Vallner](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@David\_Vallner](https://rubytalk.org/u/David_Vallner)\
**Post date:** [14 January 2006 00:50 UTC](https://rubytalk.org/t/ruby-under-cygwin-windows-paths/24084/6 "2006-01-14T00:50:05Z")

</div>

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

> **···**
>
> 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/50b3c1b275cd0c6d](http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/50b3c1b275cd0c6d)
> > 
> > I still think modifying the environment is a better approach than  
> > writing wrapper scripts.
> > 
> > cheers
> > 
> > robert

---

<div class="post-metadata">

**Author:** ![Mojca\_Miklavec](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@Mojca\_Miklavec](https://rubytalk.org/u/Mojca_Miklavec)\
**Post date:** [18 January 2006 13:48 UTC](https://rubytalk.org/t/ruby-under-cygwin-windows-paths/24084/7 "2006-01-18T13:48:50Z")

</div>

I'm sorry. I don't know how I missed this message despite a special  
notice that it was lost.

Thanks a lot.  
set RUBYLIB=/cygdrive/c/programs/texmf/scripts/context/ruby  
was the keyword which finally solved the problem.

(And the bitter experience afterwards: ruby doesn't need to be  
installed at all, only extracted to some folder and the path has to be  
set properly. I feel like a prisoner who doesn't even notice if the  
door is unlocked.)

Mojca

> **···**
>
> Robert Klemme \<shortcutter@googlemail.com\> wrote:
> 
> > 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.

---

<div class="post-metadata">

**Author:** ![Mojca\_Miklavec](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@Mojca\_Miklavec](https://rubytalk.org/u/Mojca_Miklavec)\
**Post date:** [13 January 2006 17:06 UTC](https://rubytalk.org/t/ruby-under-cygwin-windows-paths/24084/8 "2006-01-13T17:06:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Robert\_K1](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/robert_k1/32/1830_2.png) [@Robert\_K1](https://rubytalk.org/u/Robert_K1)\
**Post date:** [14 January 2006 10:01 UTC](https://rubytalk.org/t/ruby-under-cygwin-windows-paths/24084/9 "2006-01-14T10:01:41Z")

</div>

> 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

> **···**
>
> 2006/1/14, David Vallner \<david@vallner.net\>:

---

<div class="post-metadata">

**Author:** ![Thomas5](https://avatars.discourse-cdn.com/v4/letter/t/f4b2a3/32.png) [@Thomas5](https://rubytalk.org/u/Thomas5)\
**Post date:** [13 January 2006 17:50 UTC](https://rubytalk.org/t/ruby-under-cygwin-windows-paths/24084/10 "2006-01-13T17:50:59Z")

</div>

> 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://messenger.yahoo.de](http://messenger.yahoo.de)

---

<div class="post-metadata">

**Author:** ![David\_Vallner](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@David\_Vallner](https://rubytalk.org/u/David_Vallner)\
**Post date:** [13 January 2006 19:39 UTC](https://rubytalk.org/t/ruby-under-cygwin-windows-paths/24084/11 "2006-01-13T19:39:06Z")

</div>

> > 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

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

---

<div class="post-metadata">

**Author:** ![Mojca\_Miklavec](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@Mojca\_Miklavec](https://rubytalk.org/u/Mojca_Miklavec)\
**Post date:** [16 January 2006 16:37 UTC](https://rubytalk.org/t/ruby-under-cygwin-windows-paths/24084/12 "2006-01-16T16:37:03Z")

</div>

Thanks again for all the proposals, but the part with "$(cygpath -u  
%1)" doesn't work:  
ruby: No such file or derectory -- $(cygpath -u ) (Load Error)

No luck this time.

(The problem on the "bash" side, not on the "command-line" side I suppose.)

Mojca

> **···**
>
> On 1/13/06, 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.

---

<div class="post-metadata">

**Author:** ![Mojca\_Miklavec](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@Mojca\_Miklavec](https://rubytalk.org/u/Mojca_Miklavec)\
**Post date:** [15 January 2006 00:55 UTC](https://rubytalk.org/t/ruby-under-cygwin-windows-paths/24084/13 "2006-01-15T00:55:36Z")

</div>

> \>\> 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.

This command looks promising. I can't test it before monday, but I  
hope that it will solve the problem. Thanks a lot.

> 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...

It's not "ruby.exe", only "ruby". (If the problem was in ConTeXt, the  
developer would fix it within a couple of minutes/hours. If some  
software has to be installed by the admin on Windows on our computers,  
there's very little chance that it would be done before the summer.)

> 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".

Thanks for additional notes. I hope that I won't need such deeps hacks  
as writing js code to parse the command line, but let's try the above  
first and think further if it fails.

> \>\> 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.

I don't doubt that it's doable, but I would prefer trying just  
anything else before this. Besides I see no reason why to do it if the  
current installation is generally working (except for some modules  
which require additional libraries). I have enough problems with  
MikTeX installation (which is tested pretty well) - I don't dare even  
think about all the possible problems and bugs on cygwin (two were  
already fixed during my last failures to make ConTeXt work on those  
computers). Installing it on each single computer without an automated  
update mechanism (and updates come out approximately every 10 days)?  
If I ask the admin to install tetex under cygwin, it will interfere  
with the existing MikTeX and so on ... It sounds more like a nightmare  
than a serious alternative.

nobu@ruby-lang.org wrote:

> Hi,
> 
> 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?

I guess these lines do it ([http://source.contextgarden.net/newpstopdf.rb\](http://source.contextgarden.net/newpstopdf.rb%5C)):

unless defined? ownpath  
&nbsp;&nbsp;&nbsp;&nbsp;ownpath = $0.sub(/[\\\/]\w\*?\.rb/i,'')  
&nbsp;&nbsp;&nbsp;&nbsp;$: \<\< ownpath  
end

But it works ok on Windows (if there's no cygwin interference).

Thanks to everyone for suggestions, I'll report about success/failure  
on Monday once I come back to the university,  
&nbsp;&nbsp;&nbsp;&nbsp;Mojca

> **···**
>
> On 1/13/06, David Vallner wrote:
> 
> > On Fri, 13 Jan 2006 18:50:59 +0100, Thomas wrote:

---

<div class="post-metadata">

**Author:** ![David\_Vallner](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@David\_Vallner](https://rubytalk.org/u/David_Vallner)\
**Post date:** [16 January 2006 19:32 UTC](https://rubytalk.org/t/ruby-under-cygwin-windows-paths/24084/14 "2006-01-16T19:32:09Z")

</div>

The $() seems to try and execute the path... A slip of the mind? My first guess would be using backticks instead of the '$()', but that has issues with the backslashes being processed in the path I give it when trying out, and I smell rocky waters ahead. And by rocky, I mean some sed-massaging of %1 (it doesn't get much rockier), and I'll honestly admit my sed knowledge is very bad.

Did you check out that hint from that guy that posted on google groups that didn't get replicated to the list? It just might end up a lot less painful.

David Vallner

> **···**
>
> On Mon, 16 Jan 2006 17:37:03 +0100, Mojca Miklavec \<mojca.miklavec.lists@gmail.com\> wrote:
> 
> > On 1/13/06, 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.
> > 
> > Thanks again for all the proposals, but the part with "$(cygpath -u  
> > %1)" doesn't work:  
> > ruby: No such file or derectory -- $(cygpath -u ) (Load Error)
> > 
> > No luck this time.
> > 
> > (The problem on the "bash" side, not on the "command-line" side I suppose.)
> > 
> > Mojca

---

<div class="post-metadata">

**Author:** ![Thomas5](https://avatars.discourse-cdn.com/v4/letter/t/f4b2a3/32.png) [@Thomas5](https://rubytalk.org/u/Thomas5)\
**Post date:** [17 January 2006 08:32 UTC](https://rubytalk.org/t/ruby-under-cygwin-windows-paths/24084/15 "2006-01-17T08:32:27Z")

</div>

> > bash -c "ruby '$(cygpath -u %1)' %2 %3 %4 %5 %6 %7 %8 %9"
> 
> Thanks again for all the proposals, but the part with "$(cygpath -u  
> %1)" doesn't work:  
> ruby: No such file or derectory -- $(cygpath -u ) (Load Error)

Okay, this is getting somewhat OT and should probably rather go to the cygwin list. Anyway,

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

test.rb:  
p $0, "Succeeded!"

At the command line (cmd.exe):  
G:\\>ruby.bat g:\tml\src\test.rb  
"/mnt/g/tml/src/test.rb"  
"Succeeded!"

$(foo) is equivalent to `foo`. A matter of taste.

Anyway, the solution with modifying RUBYLIB or some other env variable should work too -- maybe in a wrapper of the script you're calling. In general, I think mixing cygwin & native win apps isn't a good idea which is why I would suggest to install either ruby4win or tetex4cygwin.

Cheers,  
Thomas.
