On Windows under msys (but not under linux) there is ENV['BIN']
which contains the path to the bin directory, in this case "C:\msysgit\bin"
. This is actually the same directory pointed at by /bin and /usr/bin in msys so it's exactly what I need.
Ruby 1.9.3 unexpected File behavior under msys
Вопрос
I'm trying to copy a file to "/usr/bin"
using Ruby 1.9.3 with msys on Windows 7. Msys will happily do it from it's bash-like shell - $cp testscript.rb /usr/bin
does the trick.
But from within Ruby it's completely different, and FileUtils.cp
to /usr/bin
or C:/usr/bin
both fail. The problem seems to lie in how msys and Ruby handle the paths and they don't agree on this one.
$ cd /usr/bin
$ pwd
/usr/bin
$ irb
irb(main):001:0> Dir.pwd
=> "C:/msysgit/bin"
And sure enough, FileUtils.cp("testscript.rb", "C:/msysgit/bin")
works.
Here's my question: How can I either translate between these?? I know I want to move my file into /usr/bin
and I can extrapolate to C:/usr/bin
, but I don't know how to find out that it is really C:/msysgit/bin
, and I can't just hardcode it because it needs to work not just on my setup.
I need a way to either (1) convince Dir and FileUtils and File to understand the paths the same way the msys shell does or (2) Know how to translate between them.
Has anyone else seen this problem? Any suggestions?
Решение 2
Другие советы
Your best bet in my opinion is to use
cygpath
However as you can expect this is a Cygwin program and will require the Cygwin dll, as can be seen here
$ ldd /bin/cygpath | grep /usr cygwin1.dll => /usr/bin/cygwin1.dll (0x61000000)
If this works for you, you can download cygpath
from one of
Cygwin mirrors
Example
box-soft.com/release/cygwin/cygwin-1.7.18-1.tar.bz2
After that it is very easy to convert, as you can see
$ cygpath C:/msysgit/bin /usr/bin $ cygpath -m /usr/bin C:/msysgit/bin