| www.delorie.com/archives/browse.cgi | search |
| X-Recipient: | archive-cygwin AT delorie DOT com |
| X-SWARE-Spam-Status: | No, hits=-0.5 required=5.0 tests=AWL,BAYES_20 |
| X-Spam-Check-By: | sourceware.org |
| Message-ID: | <49914E86.2060000@bonhard.uklinux.net> |
| Date: | Tue, 10 Feb 2009 09:53:10 +0000 |
| From: | Fergus <fergus AT bonhard DOT uklinux DOT net> |
| User-Agent: | Thunderbird 2.0.0.18 (Windows/20081105) |
| MIME-Version: | 1.0 |
| To: | Cygwin ML <cygwin AT cygwin DOT com> |
| CC: | Fergus <fergus AT bonhard DOT uklinux DOT net> |
| Subject: | Re: How does one find "cygdrive path" in a Win ".bat" file |
| Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
| List-Id: | <cygwin.cygwin.com> |
| List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
| List-Archive: | <http://sourceware.org/ml/cygwin/> |
| List-Post: | <mailto:cygwin AT cygwin DOT com> |
| List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
| Sender: | cygwin-owner AT cygwin DOT com |
| Mail-Followup-To: | cygwin AT cygwin DOT com |
| Delivered-To: | mailing list cygwin AT cygwin DOT com |
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/
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |