Search code examples
rubybashcygwinjruby

converting a Cygwin path a a path that ruby can understand


In my scrip I have a section that needs to change a local path name into an absolute path(not going in to it, sorry)

I am using

args+="-f "
args+="$(realpath "$relative-path") "
jruby -Ilib bin/trace.rb $args

This works for things inside the script, but when I pass this absolute file path to ruby, it does not know what to do. I can think of ways to fix this problem on my local box through string substitution. sub (C: for cygpath/c), but if I were to deploy my script to an unknown file system I could be in trouble. it needs to work on cygwin for development (I know I have to develop in widows) and unix boxes.

Question:

Is the a way that I can make my script always pass a usable path as an arg to ruby (jruby but that should not matter).

advice for a single solution or one tackles the cygwin and unix environments differently are both welcome.


Solution

  • Cygwin's cygpath command is the tool for the job. It converts between Cygwin's POSIX paths and various forms of Windows paths. It will even do the absolute path conversion for you, so:

    args+="$(cygpath -wa "$relative-path") "
    

    See cygpath's help output or man page for details on its options.