Converting POSIX Paths in Cygwin to Windows Format

Cygwin Logo

Unfortunately, Windows programs do not understand POSIX pathnames, such as the ones produced by Cygwin, e.g. “/cygdrive/c/some_folder”. Consequently you will run into problems when trying to call Windows applications from within Cygwin, or even when supplying POSIX pathnames to these programs as parameter.

Fortunately, there is an easy way to convert between POSIX pathnames and the ones used by Windows in Cygwin: cygpath to the rescue!

Thus, for instance if you want to require() a file in PHP using an absolute path the following example demonstrates how to make the correct conversion using cygpath:

PHP_REQUIRE="require('$(cygpath -aw $(pwd)/../src/config/base.php)')"
echo $PHP_REQUIRE

Or in case you just need a Windows conformant version of $(pwd):

CWD="$(cygpath -aw $(pwd))"

The -a switch tells to produce an absolute path and -w to produce Windows conformant pathnames. That’s it!

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.