This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How does one find "cygdrive path" in a Win ".bat" file


This might not be quite what you are after, but possibly will provide a starting point. My Cygwin installation is mounted in the root directory of a portable drive so, depending on where I am, the drive might end up being D: or F: or G: or M: or ... The lines following are the first few lines in a .cmd file located at \ that will correctly implement commands under /bin (or anywhere else under /) because the correct drivename is correctly identified whether you start the .cmd file (a) from a Command Prompt (b) using Start -> Run -> .. or (c) by double-clicking in Explorer.

(It's to allow for both (b) and (c) that the rather awkward pair of if() commands are needed.)

set DOS_CMD=%0
set CWD=%CD%
set DN=%CWD:~0,2%
if (%DOS_CMD:~1,1%)==(:) set DN=%DOS_CMD:~0,2%
if (%DOS_CMD:~2,1%)==(:) set DN=%DOS_CMD:~1,2%
%DN%\bin\{command}

More generally, a user's Cygwin installation might be located on a portable drive under \dir1\dir2\dir3\.. and then in general the startup command file will need to "know" or "discover" not just the drivename but the pathname: ie CWD.

NB I have not found a foolproof way of doing this other than by locating the command file at \dir1\dir2\dir3\.. (i.e. at / with respect to the Cygwin installation) and this might be too specialised for what you want to do, but if your quest is more general than this, I think

> you have to rely on external data and heuristics

as earlier suggested.

Fergus



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]